Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Router: returning notFound() from generateMetadata does not change the response status code to 404 if there's a loading.tsx component #75543

Closed
felipedeboni opened this issue Jan 31, 2025 · 0 comments
Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). Loading UI and Streaming Related to loading UI (loading.tsx) and streaming. Metadata Related to Next.js' Metadata API.

Comments

@felipedeboni
Copy link

Link to the code that reproduces this issue

https://github.com/felipedeboni/next-404

To Reproduce

Go to: https://next-404-ten.vercel.app/with-loading

  • not found is rendered
  • response status is 200 OK.

Go to: https://next-404-ten.vercel.app/with-parent-loading

  • renders the page as expected.

Go to: https://next-404-ten.vercel.app/with-parent-loading/children

  • not found is rendered
  • response status is 200 OK.

Current vs. Expected behavior

When returning notFound from generateMetadata I would expect the response to have a 404 Not Found status in order to allow pages to be removed from Google Index and others...

The alternative is awful, in middleware:

  • Check if it's a bot. If not just continue.
  • Check if resource exists. If it does continue.
  • Send 404 Not Found.

However this is going to make things slower for bots, making the web vitals score lower given there's no fetch cache on middleware and fetch calls made on middleware aren't shared (cached) with the page itself.

For regular access I it's fine to have 200 OK and just show not found component (or default), however for bots we need the proper status.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 18:56:34 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6020
  Available memory (MB): 65536
  Available CPU cores: 12
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.21
  pnpm: 9.4.0
Relevant Packages:
  next: 15.1.6 // Latest available version is detected (15.1.6).
  eslint-config-next: 15.1.6
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Loading UI and Streaming, Metadata

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed)

Additional context

No response

@github-actions github-actions bot added Loading UI and Streaming Related to loading UI (loading.tsx) and streaming. Metadata Related to Next.js' Metadata API. labels Jan 31, 2025
@samcx samcx added the Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). label Feb 1, 2025
@vercel vercel locked and limited conversation to collaborators Feb 1, 2025
@samcx samcx converted this issue into discussion #75563 Feb 1, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). Loading UI and Streaming Related to loading UI (loading.tsx) and streaming. Metadata Related to Next.js' Metadata API.
Projects
None yet
Development

No branches or pull requests

2 participants