🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@Rani367
Copy link

@Rani367 Rani367 commented Dec 10, 2025

What?

This PR fixes an issue where notFound() (and other HTTP access fallback errors like forbidden()/unauthorized()) would cause "Connection closed" errors when cacheComponents: true is enabled and the page has a Suspense boundary with an async component.

Why?

When cacheComponents is enabled and a page is prerendered, subsequent requests use DynamicState.DATA mode which only sends RSC data without re-rendering the HTML shell. However, when notFound() is thrown during this RSC render, the prerendered HTML doesn't contain the not-found component, causing the client to receive an incomplete stream and display "Connection closed" errors.

How?

This fix buffers the RSC stream in DynamicState.DATA mode to detect HTTP access fallback errors. After consuming the stream:

  1. Check reactServerErrorsByDigest for any errors with the HTTP_ERROR_FALLBACK_ERROR_CODE prefix
  2. If no such errors exist, send the buffered RSC data as before
  3. If such errors are found, set the appropriate status code and fall through to the full dynamic render path which properly handles the not-found page

Test Plan

Added two test cases:

  • not-found-suspense: Tests notFound() thrown inside a Suspense boundary
  • not-found-with-layout-suspense: Exact reproduction of the issue - notFound() in page with async component in layout's Suspense

Fixes #86251

When cacheComponents is enabled and a page is prerendered, subsequent
requests use DynamicState.DATA mode which only sends RSC data without
re-rendering the HTML shell. However, when notFound() (or forbidden/
unauthorized) is thrown during this RSC render, the prerendered HTML
doesn't contain the not-found component, causing Connection closed
errors.

This fix buffers the RSC stream in DATA mode to detect HTTP access
fallback errors. If such errors are found, it falls through to the
full dynamic render path which properly handles the not-found page.

Fixes vercel#86251
@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Dec 10, 2025

Allow CI Workflow Run

  • approve CI run for commit: 7759d68

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

notFound breaks Suspense in layout with cacheComponents enabled

2 participants