Skip to main content

2026-07-17 · 4 min read

Next.js params is now a Promise: a 404 trap that tsc and the build both miss

Next.jsDebugging

Translated from the Chinese original: read it in Chinese

While adding a /projects/[slug] dynamic route to my portfolio I ran into a well-hidden trap. I am writing it down because of one thing about it: every automated check passed, and the breakage only showed up when I opened the pages in a browser.

How it started

I wrote the App Router dynamic page the way I had written it countless times before:

export default function ProjectDetailPage({
  params,
}: {
  params: { slug: string };
}) {
  const project = projects.find((p) => p.slug === params.slug);
  if (!project) notFound();
  // ...
}

generateStaticParams() returned the slugs of all 7 projects, and next build finished with:

├ ● /projects/[slug]
│ ├ /projects/foodlens-advisor
│ ├ /projects/ticketing-system
│ ├ /projects/frc-robot
│ └ [+4 more paths]

tsc --noEmit reported nothing. Everything looked normal, so I committed, pushed and deployed.

In reality every page was a 404

Only when I ran curl against each path did I find out: even valid slugs returned 404. I looked at .next/server/app/projects/foodlens-advisor.meta:

{
  "status": 404,
  ...
}

Not one broken page. All 7 of them, including valid slugs that clearly had matching data.

Root cause: params is now a Promise

Starting with Next.js 15, params (and searchParams) in the App Router became an asynchronous Promise, to pave the way for features such as Partial Prerendering. Version 15 kept a temporary synchronous compatibility layer: the old style still got the value and only printed a warning. Next.js 16 removed synchronous access entirely. This site was on 16 when it happened (16.2.9 in package.json), so the old style did not warn. It simply got no value.

The old annotation { params: { slug: string } } still passes type checking, structurally. TypeScript does not complain about a missing Promise<...>, because reading .slug is not a syntax error in itself. The value is just always undefined, since params is really a Promise object and not the resolved data.

So projects.find((p) => p.slug === params.slug) never finds anything, because params.slug is always undefined, and notFound() fires every time, valid slugs included.

The fix

type ProjectPageProps = { params: Promise<{ slug: string }> };

export default async function ProjectDetailPage({ params }: ProjectPageProps) {
  const { slug } = await params;
  const project = projects.find((p) => p.slug === slug);
  if (!project) notFound();
  // ...
}

generateMetadata needs the same change: make it async and await params.

What I learned

  • Type checking cannot catch something that is structurally compatible but semantically wrong. params.slug is valid TypeScript in both versions. One gets a string and the other gets undefined.
  • "Generated N pages" in the next build output does not mean those pages work. The build only confirms that static output was produced. It does not verify that the output is correct.
  • What finally caught it was running curl against every real path and reading the HTTP status code. Since then, for any new route, I look at the build log and I also make at least one real request to confirm the status.

Follow-up (2026-11-29): looking back after moving to 16.4

Why this only bites on 16. The original post said "starting with Next.js 15". More precisely: 15 turned params into a Promise but kept the old synchronous style working so people could migrate gradually, and the official upgrade guide for 16 states that synchronous access is fully removed. On 15, params.slug would have returned the value with a warning in development, and this 404 would never have appeared.

It is not only page.tsx. The 16 upgrade guide lists everything affected: the params received by layout, page, route and default, the searchParams of page, and the image-generating files opengraph-image, twitter-image, icon and apple-icon, whose params also became a Promise in 16. The share image for my project pages (/projects/[slug]/opengraph-image.tsx) has to await params as well. The project now has 11 files that use params: Promise<…>.

You do not have to write the type by hand. Since Next.js 15.5, next typegen generates a global PageProps<'/projects/[slug]'> from your routes, with the type of params inferred from the folder name, so there is no need to hand-write { params: Promise<{ slug: string }> }. This site still writes it by hand and has not switched yet.

"Make one real request" later became an automated test. The original post ended with a promise to remember to curl new routes. Remembering is not enough:

  1. After a separate incident where Chinese-character URLs returned 404 (write-up, in Chinese), e2e/sitemap.spec.ts requests every URL in the sitemap and expects 200 for all of them (129 URLs at the moment)
  2. After enabling Cache Components, dynamic routes export ensureStatic = "navigation", so a slug that is not in the list returns a real 404. Without it, the server streams the page shell first, the status is already 200, and only afterwards does it discover there is nothing to show

The bug in this post is "a valid URL returns 404". Point 2 guards against the opposite, "a missing URL returns 200". You need tests that hit real URLs in both directions to catch both.

Related commits: 7e70d0a (GitHub)

Type to search projects and posts too