Next.js soft 404 errors on a Sanity site: causes and fixes

By Nayan Kyada · · 6 min read

Part of The Sanity + Next.js Guide

If Google Search Console shows "Soft 404" against URLs on your Next.js and Sanity site, the cause is almost always the same: a page that has no content to show still answers with HTTP 200. The server says the page is fine, the page says nothing is here, and Google believes the page.

This post covers how that happens on Sanity-backed sites, how to confirm it, and the fix order I use. It sits next to Next.js pages not indexed by Google, which covers the wider indexing picture.

What a soft 404 looks like on a Sanity site

Typical symptoms:

  • Search Console lists URLs under Page indexing as "Soft 404".
  • Visiting a deleted or mistyped slug shows a blank layout, an empty heading, or a friendly "Nothing found" message, but the network tab says 200.
  • Old URLs from unpublished or renamed documents stay in Google's report for months.
  • Category or tag pages with zero posts render a header and an empty grid.

A real 404 is a status code, not a message. Visitors cannot tell the difference, which is why this survives for years unnoticed.

Why ignoring it costs you

Google drops soft 404 URLs from the index, which is fine for truly dead pages. The damage is elsewhere. Crawl budget goes to dead URLs, your Search Console reports fill with noise so real problems hide, and if the empty page is a page you wanted indexed (for example a document that fails to resolve because of a query bug), you lose it silently. If you recently changed slugs, also read Sanity slug changes causing 404s.

Cause 1: the page never calls notFound()

This is the most common one. The GROQ query returns null for an unknown slug, and the component handles null by rendering less, not by signalling a 404.

Broken pattern:

// app/blog/[slug]/page.tsx
import { client } from '@/sanity/lib/client'
import { postQuery } from '@/sanity/lib/queries'
 
export default async function PostPage({
  params,
}: {
  params: Promise<{ slug: string }>
}) {
  const { slug } = await params
  const post = await client.fetch(postQuery, { slug })
 
  // Unknown slug: post is null, page still returns 200
  return (
    <article>
      <h1>{post?.title}</h1>
    </article>
  )
}

Fix: call notFound() as soon as the data is missing, and do the same in generateMetadata so the metadata does not render a default title for a page that does not exist.

// app/blog/[slug]/page.tsx
import { notFound } from 'next/navigation'
import { client } from '@/sanity/lib/client'
import { postQuery } from '@/sanity/lib/queries'
 
export const dynamicParams = true
 
export default async function PostPage({
  params,
}: {
  params: Promise<{ slug: string }>
}) {
  const { slug } = await params
  const post = await client.fetch(postQuery, { slug })
  if (!post) notFound()
 
  return (
    <article>
      <h1>{post.title}</h1>
    </article>
  )
}

Add an app/not-found.tsx so the 404 page is branded and useful. In the App Router, notFound() renders the closest not-found file and sets the 404 status.

Cause 2: a try/catch that swallows the failure

I often see data helpers that wrap the Sanity fetch in try/catch and return an empty object on error. A network failure, a wrong token, or a bad query then looks identical to a missing page, and the empty object is truthy, so a null check never fires. Let genuine errors throw so you get a 500 and an alert, and reserve notFound() for the case where the query succeeded and returned nothing.

Cause 3: streaming after the status line is sent

If the page wraps its main data fetch inside a Suspense boundary and calls notFound() inside that boundary, the response may already have started streaming with a 200. Next.js cannot change the status afterwards. It adds a noindex meta tag to the streamed output instead, which Google generally respects, but you lose the clean 404.

The rule I follow: fetch the document that decides whether the page exists before any Suspense boundary, in the page component itself. Stream the slow, secondary sections (related posts, comments, recommendations) behind Suspense. Check the response status in a terminal after changing this, because it is easy to assume it works.

Cause 4: empty listing pages

Category, tag, author, or paginated pages with no results are the second large source. Decide a policy per route:

  • A category document exists but has no posts: return 200 with a useful message, or 404 if you do not want it indexed.
  • Page number beyond the last page: return 404.
  • Tag slug that does not exist in Sanity: 404.

For pagination, check the total count from the same query and call notFound() when the page is out of range. A page=9999 URL should never return 200.

Cause 5: catch-all routes and missing generateStaticParams control

Catch-all segments such as app/[...slug]/page.tsx accept every URL. Without a null check they answer 200 for anything. Even with the check, make sure the GROQ filter includes the document type and a defined slug, otherwise a draft or a wrong document type can match. Also exclude drafts from published queries, since drafts with the same slug can leak into results.

How to verify the fix

Check the status code, not the page. Use a terminal:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/blog/this-slug-does-not-exist

Expect 404. Then test a real slug (200), an unpublished document slug (404), an out-of-range page number (404), and an empty category. In Search Console, use URL Inspection on a few flagged URLs, then validate the fix in the Page indexing report. Re-crawl takes days to weeks, so do not expect the report to clear immediately.

For a full pass, crawl the site with any crawler that reports status codes and compare against your sitemap. Every sitemap URL must return 200. If your sitemap contains slugs that now 404, fix the sitemap query as well, and use redirects for URLs that moved rather than leaving them dead. Broken document links are a related failure mode covered in Sanity broken references crashing Next.js pages.

What to ask a developer

If you are hiring someone to fix this, ask:

  • Which routes can return a page for data that does not exist, and how will you list them?
  • Will you verify status codes with real requests, not just by looking at the page?
  • How do empty listings and out-of-range pagination behave after the change?
  • Will redirects be added for URLs that used to be live and now 404?

A developer who answers with status codes and a route list understands the problem. One who offers only to add a nicer 404 design does not.

This is part of the work covered in a Performance & Sanity audit, from $800, which includes a route-by-route status code check. If your Search Console report is full of soft 404s and you want it traced and fixed, that is work I do, and you can see the options on the services page. For a general look at what such a review covers, see what a paid Next.js website audit includes.

Frequently asked questions

What is a soft 404 in Next.js?

A soft 404 is a page that tells the visitor nothing exists but still returns HTTP 200. Google Search Console flags these because the status code and the content disagree.

Why does my Sanity page return 200 when the document does not exist?

Usually the GROQ query returns null and the page component renders an empty shell or a custom not-found message instead of calling notFound(). Only notFound() produces a real 404 response.

Do soft 404s hurt SEO?

Google treats them as errors and drops those URLs from the index, but they also waste crawl budget and can hide real indexing problems. On a large Sanity site, thousands of them make Search Console reports hard to trust.