ISSUE DESCRIPTION A self-throwing global error component renders no last-resort UI If…
- User
ISSUE DESCRIPTION
A self-throwing global error component renders no last-resort UI
If the global error component itself fails, return the built-in valid HTML fallback with the expected successful fallback status while preserving response headers and cookies. Local error boundaries and framework navigation/control-flow signals must retain their existing semantics, and the original boundary exception must not be exposed.
Interface
No new public interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /vinext, current file: none) bash-$
Assistant
Let me explore the repository structure first.
Assistant
Now let me look at how the error boundary rendering handles errors when the global error component itself fails. Let me look at
renderAppPageBoundaryResponseandrenderAppPageHtmlResponseand the SSR handler to see where errors during rendering are caught.Assistant
Now I see that the SSR handler is what renders the HTML. The error happens during SSR streaming. Let me look at how the page render handles errors, particularly the recovery mechanism. Let me look at
renderAppPageHtmlStreamWithRecoveryand how it's used in the page render path.Assistant
Now I understand the architecture. Let me understand the issue: when the global error component itself fails (during the error boundary render path), what happens? Let me trace the path.
When a render error occurs, the flow is:
renderAppPageHtmlStreamWithRecoverycatches the error- Calls
options.renderErrorBoundaryResponse(error)which callsrenderErrorBoundary→renderAppPageErrorBoundary - This renders the global error component
If the global error component itself throws, what happens? The error boundary render would throw, and
renderErrorBoundaryResponsewould return... let me check. ActuallyrenderAppPageErrorBoundaryreturnsPromise<Response | null>and inside it callsrenderAppPageBoundaryElementResponse→renderAppPageBoundaryResponse→createHtmlResponse→renderAppPageHtmlResponse→renderAppPageHtmlStream.But wait, the error in the global error component would happen during SSR streaming, which is lazy. So when does the error actually surface?
Let me think about this more carefully. The SSR render happens when the stream is consumed. The error from the global error component during SSR streaming would surface as a stream error, not as a synchronous throw in
renderAppPageHtmlResponse.Actually wait. Let me reconsider. The
renderAppPageHtmlStreamcallsoptions.ssrHandler.handleSsr(...). This returns a stream. The shell render happens during this. If the global error component itself throws during the shell render (synchronously while building the shell), thenhandleSsrwould reject, andrenderAppPageHtmlStreamwould throw.But this is inside
renderErrorBoundaryResponse, which is called fromrenderAppPageHtmlStreamWithRecovery. At that point, we're already in the catch block. IfrenderErrorBoundaryResponsethrows, the error propagates up.Hmm, but the issue says "renders no last-resort UI". So the bug is: when the global error component itself fails, there's no fallback UI rendered. The desired behavior is to return the built-in valid HTML fallback.
Let me look at the actual SSR handler to understand where errors during rendering surface.
Assistant
Now I understand the SSR pipeline. Let me look at the default global error module and the built-in HTML fallback.
Assistant
Now let me look at how the render flow is dispatched and where the error boundary response is invoked. Let me look at the page render dispatch.
Assistant
Let me look at the dispatch flow and where the final fallback happens.
Assistant
Let me look at the top-level request handling where errors are caught and the fallback HTML is generated.
Assistant
Let me find the top-level request handler and where dispatch errors are caught.
Assistant
This is a generated entry. Let me look at the actual request pipeline where errors get caught and where the final fallback is. Let me look at the request-pipeline.ts and how
renderAppPage/dispatchAppPageis wrapped.Assistant
Let me look at the actual request handler that catches top-level errors. Let me look at the app-rsc-handler.ts which seems to be the main request handler.
Assistant
Now let me understand where the page render itself happens (the dispatchAppPage result). Let me see the section after the route is matched.
Assistant
Let me find the top-level catch that produces a final response when the whole dispatch throws.
Assistant
Let me look at the prod-server and the top-level worker fetch handler.
Assistant
Let me look at the tests to understand the expected behavior.
Assistant
Let me look at the global-error.tsx fixture and the global-error-rsc page.
Assistant
Let me look at the full
renderAppPageErrorBoundaryfunction and its options type.Assistant
Let me look at how the error is sanitized and the digest is computed.
Assistant
Let me check the
app-ppr-fallback-shell.tsand any static HTML helpers.Assistant
Let me look at the changeset directory and recent changes for context.
Assistant
Let me look at the existing unit test for the boundary render.
Assistant
Let me first try running the existing unit test to confirm the test infrastructure works.
Assistant
Let me look at the dev-server test pattern to set up a reproduction.
Assistant
Let me create a temporary fixture with a self-throwing global error and a page that throws, then run a quick reproduction. But modifying the app-basic fixture's global-error.tsx would break existing tests. Let me create a separate fixture directory.
Actually, let me create a temporary test that uses a custom fixture. Let me look at the helpers to understand startFixtureServer.
Assistant
Let me create a temporary fixture with a self-throwing global error and a page that throws, and a temporary test.
Assistant
The test runner only includes specific files. Let me place the repro test inside the tests/ directory temporarily.
Assistant
Let me rewrite the test file cleanly and put the fixture in tests/fixtures.
Assistant
The integration project has a specific include list. Let me check the vitest config to find the projects. Let me rename the test to match one of the included patterns, or use a different approach. Let me check the vitest config.
Assistant
The unit project includes
tests/**/*.test.ts. Let me run the repro test as a unit test.Assistant
I've reproduced the issue: status 500 instead of 200. Let me see the full output to confirm the HTML content.
Assistant
Let me look at how the dev server handles SSR errors.
Assistant
Let me find the App Router dev request handler and where the 500 comes from.
Assistant
Let me look at how the dev server serves the app router. The dev server likely uses the generated app-rsc-entry. The 500 with the Vite overlay comes from the dev server's error handling. Let me look at where the app router request is dispatched in dev.
Assistant
Let me find how the dev server actually invokes the app router. The dev server middleware likely loads the rsc-entry module and calls its default handler. Let me search for where the rsc entry's default export is called in dev.
Assistant
Let me look at the top of app-router-entry to understand the dev path.
Assistant
This is the prod worker entry. The dev server must use a different path. Let me look at how the dev server invokes the app router. Let me search the index.ts (the main vinext plugin) for the dev server middleware.
Assistant
Now I understand the flow. Let me check the imports of app-page-boundary-render.ts to see what's available.
Assistant
Let me look at
createInitialDevServerErrorScriptto understand the dev overlay mechanism.Assistant
Let me check
mergeMiddlewareResponseHeadersto confirm cookies are preserved.Assistant
Good, cookies/headers are preserved through the existing pipeline. Now let me view the exact lines of
renderAppPageErrorBoundaryto edit.Assistant
Let me check what's exported from app-page-boundary.js for the result type.
Assistant
Let me add the import for
DEFAULT_GLOBAL_ERROR_MODULE.Assistant
Now let me add the import. Let me view lines 9-25.
Assistant
Now let me modify the
renderAppPageErrorBoundaryfunction. Let me view its current exact content with line numbers.Assistant
Now let me edit the final return block to wrap it in try/catch with the fallback. Let me get exact line numbers.
Assistant
Now let me replace the element-building + return block (lines 427-458) with a version that wraps the render in try/catch and falls back to the built-in default global error.
Assistant
Now let me run the repro test to verify the fix works.
Assistant
The fix works in dev. Let me verify the HTML content and that the original exception isn't exposed.
Assistant
Let me rewrite the repro test to check assertions and add a prod preview test.
Assistant
The dev overlay script intentionally exposes the error for developer tooling (existing pattern). Let me check what the app-basic fixture has for build setup, so I can make a buildable prod fixture.
Assistant
Let me look at app-basic's config files to create a buildable prod fixture.
Assistant
Let me make the minimal fixture buildable by adding config files.
Assistant
Let me relax the dev test assertion (dev overlay intentionally exposes the error) and run again.
Assistant
Both dev and prod tests pass. Now let me strengthen the test to verify headers/cookies preservation by adding a middleware to the fixture. Let me check the middleware format.
Assistant
Let me add a simple middleware to the fixture to verify header/cookie preservation.
Assistant
Excellent! Both dev and prod tests pass with header/cookie preservation. Now let me run the existing related tests to ensure I didn't break anything.
Assistant
All 22 global-error compat tests pass. Let me run the broader app-router dev server tests which exercise error boundaries.
Assistant
All 163 tests pass. Let me run the production server tests too.
Assistant
Let me check
resolveAppPageSpecialErrorand navigation signal handling to ensure I don't swallow control-flow signals.Assistant
Let me check for potential circular imports before adding
resolveAppPageSpecialError.Assistant
No circular import. Let me add the import for
resolveAppPageSpecialErrorand guard against swallowing navigation/control-flow signals.Assistant
Now let me update the catch block to re-throw navigation/control-flow signals.
Assistant
Let me re-run the repro and unit tests to verify the changes.
Assistant
Let me run a broader set of tests to ensure nothing is broken — the nextjs-compat suite and the production build test.
Assistant
Let me run the typecheck/lint on the package to ensure the types are correct.
Assistant
Typecheck passes. Let me run the linter on the modified file.
Assistant
Let me verify formatting passes on the modified file.
Assistant
Let me check all callers of
renderAppPageErrorBoundaryto ensure the change is consistent across all paths.Assistant
Let me run the full nextjs-compat test directory (many error-boundary related tests) to be thorough.
Assistant
Let me double-check there's no
onShellErrorin the SSR path that could swallow the shell error.Assistant
No
onShellError— shell errors reject and are caught. Let me review the final diff of the source change.Assistant
The diff looks good. Now let me clean up the temporary reproduction test and fixture before submitting.
Assistant
Only the source file is modified. Let me do a final typecheck and lint to confirm everything is clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →