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
I'll start by exploring the repository to understand the codebase and locate relevant files related to error handling, global error component, and fallback UI. Let's first get an overview.
- Assistant
Let me look at the directory structure more carefully.
- Assistant
Let me explore the packages directory to understand the structure better.
- Assistant
Let me look at the vinext package structure.
- Assistant
Let me look at the source code structure of vinext.
- Assistant
Let me search for global error component and error boundary related code.
- Assistant
Let me look at the source files for error handling, particularly around global error boundaries. Let me look at the server directory and the relevant files.
- Assistant
We're already in packages/vinext. Let me just list the server directory.
- Assistant
Let me look at the key files related to the issue. Let me start by examining the app-fallback-renderer.ts, app-page-boundary.ts, and app-page-stream.ts files as they seem relevant to the issue about global error component and fallback UI.
- Assistant
Now let me look at the
app-page-boundary-render.tsandapp-page-boundary.tsto understand how error boundaries work. - Assistant
Now let me look at the boundary render function more closely, especially the
renderAppPageErrorBoundaryfunction. Let me also check theapp-page-boundary.tsfile. - Assistant
Let me now understand the issue better. The issue says:
"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."
- Assistant
Now let me look at the
default-global-error-module.tsand its related components to understand what the default global error looks like: - Assistant
Let me look at the shim for the default global error to understand what it renders.
- Assistant
Let me examine the error-boundary.tsx file:
- Assistant
Now let me look at the test files related to this functionality to understand what behavior is expected:
- Assistant
Let me look at the test files to understand the expected behavior.
- Assistant
Now let me look at the
error-boundary.test.tsfile: - Assistant
Let me also look at how Next.js handles the "self-throwing global error component" case:
- Assistant
Let me look at the
app-page-render.tsto understand how errors are handled during rendering: - Assistant
Let me look at the specific section around lines 816-882 to understand how the error boundary response is rendered:
- Assistant
Let me search for how
renderErrorBoundaryResponseis set up in the dispatch/wiring: - Assistant
Let me look at the dispatch function to understand how renderErrorBoundaryResponse is implemented:
- Assistant
Let me find the
renderErrorBoundaryPageto understand the full flow: - Assistant
Let me look at lines 795-810 to see the full context:
- Assistant
Let me search for where
renderErrorBoundaryPageis actually implemented in the route wiring: - Assistant
Let me search more broadly.
- Assistant
Let me look at
app-page-request.tswhere it callsrenderErrorBoundaryPage: Rerendering with Global ErrorThe issue is about a self-throwing global error component. Let me look at the
shouldRerenderAppPageWithGlobalErrorfunction and how the error boundary response is generated. Let me trace the flow:- When an error occurs during SSR rendering,
renderAppPageHtmlStreamWithRecoverycatches it and callsrenderErrorBoundaryResponse. - If the error is a "special" error (redirect/notFound), it's handled.
- Otherwise,
renderErrorBoundaryResponsecallsrenderAppPageErrorBoundarywhich renders the error component. - If the error is caught by the global error boundary (isGlobalError=true), it renders the global error component.
- When an error occurs during SSR rendering,
- Assistant
Let me look at one file at a time.
- Assistant
Let me look at the RSC entry to understand how
renderErrorBoundaryPageis set up: - Assistant
Now let me understand the flow when the global error component itself throws. Let me look at the
renderAppPageBoundaryResponsefunction again and the SSR rendering: - Assistant
Let me read the
renderAppPageErrorBoundaryfunction more carefully: - Assistant
Now let me look at
renderAppPageBoundaryElementResponseandrenderAppPageBoundaryResponseto understand the error flow: - Assistant
Let me look at the default global error component to understand what to use as fallback:
- Assistant
Now let me understand how the RSC entry handles rendering the error boundary:
- Assistant
Now let me look at the existing tests to understand what tests already exist for this scenario:
- Assistant
Let me look at the relevant test files:
- Assistant
Now let me look at how the SSR handler processes the RSC stream to understand error propagation:
- Assistant
Let me look at the http-error-responses to understand how built-in responses are constructed:
- Assistant
Now let me understand how Next.js handles this. Let me look at the test fixtures for self-throwing global error:
- Assistant
Let me look for tests about self-throwing global errors:
- Assistant
Let me search for existing test patterns related to the "self-throwing" scenario:
- Assistant
Let me search more broadly for tests related to the global error boundary rendering:
- Assistant
Let me look at
app-page-render.test.tsfor tests related to self-throwing global errors: - Assistant
Let me look at the test around line 524:
- Assistant
Let me look for existing tests that test self-throwing behavior or check the test structure:
- Assistant
Let me look at the stream test for the fallback behavior:
- Assistant
Now let me look at the relevant test cases to understand what specific tests exist for the self-throwing global error scenario:
- Assistant
Now I have a good understanding of the issue. Let me look at how the
renderAppPageBoundaryResponsehandles errors and trace through the complete flow when the global error component itself throws: - Assistant
Now I understand the issue. Let me trace the problem:
- When a page error occurs,
renderAppPageErrorBoundaryrenders the global error component - If the global error component itself throws during rendering (RSC or SSR), the error propagates uncaught
- The
renderAppPageBoundaryElementResponse→renderAppPageBoundaryResponse→ SSR pipeline has no catch for this - The
renderAppPageHtmlStreamWithRecoveryrecovery would try to render the error boundary again, creating an infinite loop or empty response
The fix: wrap the
renderAppPageBoundaryElementResponsecall inrenderAppPageErrorBoundarywith a try-catch for the global error case, returning a built-in valid HTML fallback.Let me now implement the fix:
- When a page error occurs,
- Assistant
Let me check if there are any existing tests for self-throwing global error:
- Assistant
Let me look at how the existing test handles global error and understand what test infrastructure exists:
- Assistant
Now I understand the issue. Let me trace through the problem:
- When a page error occurs and no local error.tsx catches it,
renderAppPageErrorBoundaryis called - It resolves to the global error component
- The element is created and passed to
renderAppPageBoundaryElementResponse - If the global error component itself throws during RSC/SSR rendering, the error propagates uncaught
- There's no fallback - no last-resort UI is rendered
The fix: wrap the
renderAppPageBoundaryElementResponsecall inrenderAppPageErrorBoundarywith a try-catch for the global error case. If it fails, return a built-in valid HTML fallback with status 200, preserving response headers and cookies.Let me implement the fix:
- When a page error occurs and no local error.tsx catches it,
- Assistant
Let me now understand the full flow by looking at how errors propagate through the rendering pipeline. Let me check
app-page-render.tsaround the error boundary rerendering: - Assistant
Now I understand the full picture. Let me trace the problem:
- When a page error occurs,
renderAppPageErrorBoundaryrenders the global error component - If the global error component itself throws during rendering, the error propagates from
renderAppPageBoundaryElementResponse - In the main render flow,
shouldRerenderAppPageWithGlobalErrordetects the captured RSC error and callsrenderErrorBoundaryResponse→renderAppPageErrorBoundary - But if the global error component keeps failing, there's no last-resort fallback
The fix: In
renderAppPageErrorBoundary, wrap therenderAppPageBoundaryElementResponsecall in a try-catch for the global error case. If it fails, return a built-in valid HTML fallback with status 200, preserving response headers and cookies.Let me also look at what the
middlewareContexttype looks like: - When a page error occurs,
- Assistant
Now let me look at the
app-page-response.tsto understand themiddlewareContext: - Assistant
Now let me look at the
pages-default-404.tsto understand the pattern for static HTML fallbacks: - Assistant
Now I have a clear understanding of the issue. Let me trace the problem:
- When a page error occurs with no local error boundary,
renderAppPageErrorBoundaryrenders the global error component - If the global error component itself throws during rendering (RSC or SSR), the error propagates uncaught
- The recovery in
renderAppPageHtmlStreamWithRecoverywould tryrenderErrorBoundaryResponseagain, which calls back torenderAppPageErrorBoundarywith the same failing global error component, creating a loop or empty response
The fix: In
renderAppPageErrorBoundary, whenerrorBoundary.isGlobalErroris true, wrap therenderAppPageBoundaryElementResponsecall in a try-catch. If it fails, return a built-in valid HTML fallback with status 200, preserving response headers and cookies.Let me implement the fix:
- When a page error occurs with no local error boundary,
- Assistant
Now I need to add the
buildGlobalErrorFallbackResponsefunction. Let me check what imports are available: - Assistant
I need to add the
buildGlobalErrorFallbackResponsefunction. Let me look at how middleware headers are merged elsewhere: - Assistant
Now I need to create the
buildGlobalErrorFallbackResponsefunction. Let me add it to the file: - Assistant
I see there are duplicate imports. Let me fix that and add the
buildGlobalErrorFallbackResponsefunction: - Assistant
There are duplicate imports. Let me fix them:
- Assistant
Good, the duplicates are removed. Now I need to add the
buildGlobalErrorFallbackResponsefunction at the end of the file: - Assistant
Now I need to add the
buildGlobalErrorFallbackResponsefunction. Let me add it after therewriteClientHookErrorfunction: - Assistant
I see there's a duplicate
rewriteClientHookErrorfunction. Let me fix that: - Assistant
Good. Now let me also check if
renderAppPageHttpAccessFallbackneeds the same protection. Let me look at the code: - Assistant
Let me look at the end of
renderAppPageHttpAccessFallbackand add similar protection: - Assistant
The
renderAppPageHttpAccessFallbackalso has the global error boundary wrapping (viawrapRenderedBoundaryElementwithincludeGlobalErrorBoundary: true). If the global error component itself fails there, the error will propagate throughrenderAppPageBoundaryElementResponseand eventually reach the error handling inrenderAppPageErrorBoundary.However, for HTTP access fallbacks (not-found/forbidden/unauthorized), I should also add similar protection since the same rendering pipeline applies. Let me add a try-catch for that case too:
- Assistant
I see there's an extra
}on line 389. Let me check the context: - Assistant
There's an extra
}on line 389. Let me fix it: - Assistant
Let me check lines 386-392:
- Assistant
There's still an extra
}on line 389. Let me fix it: - Assistant
Now let me verify the full file to make sure everything is correct:
- Assistant
Now let me run the existing tests to make sure nothing is broken:
- Assistant
Let me figure out the correct test runner command.
- Assistant
Let me use the correct test command:
- Assistant
Let me find the test runner
- Assistant
Let me try running the tests with npx or node_modules/.bin:
- Assistant
Let me check the test runner setup more carefully.
- Assistant
Let me find the test runner. It seems like
vpis a custom tool. Let me check: - Assistant
Now let me verify the file is syntactically valid and run the existing tests. First, let me check for TypeScript errors:
- Assistant
Now let me run the existing tests to make sure our changes don't break anything:
- Assistant
There's a parse error - the
renderAppPageErrorBoundaryfunction is missing its closing brace. Let me check: - Assistant
The
renderAppPageErrorBoundaryfunction is missing its closing brace. Let me fix this: - Assistant
I see there are duplicate
status: 200,and duplicate comments. Let me fix the file properly. Let me look at the full file and fix all issues: - Assistant
Let me fix the duplicate lines:
- Assistant
Let me verify the file is syntactically correct now:
- Assistant
All 15 existing tests pass. Let me run other related tests:
- Assistant
Let me also run the app-fallback-renderer and app-page-boundary tests:
- Assistant
Let me also run the error-boundary test:
- Assistant
Let me run the app-page-render test:
- Assistant
All existing tests pass. Now let me verify the fix works correctly by creating a test script:
- Assistant
Let me run this test:
- Assistant
The test needs to be in the tests directory. Let me copy it there:
- Assistant
The first two tests pass. The third test fails because the HTTP access fallback returns null when there's no not-found boundary module. Let me fix the test:
- Assistant
Let me run the test again:
- Assistant
The HTTP access fallback test fails because the self-throwing global error component is only used as the
fallbackprop in the ErrorBoundary wrapper, which is only applied for RSC requests. For non-RSC SSR requests, the component isn't rendered in the tree. Let me fix the test: - Assistant
Let me run the updated test:
- Assistant
All 4 tests pass! Let me run all the existing tests to make sure nothing is broken:
- Assistant
All 139 existing tests pass plus our 4 new tests. Let me now clean up the temporary test file:
- Assistant
Let me also clean up the temp file:
- Assistant
Now let me verify the final state of the file:
- Assistant
Let me check the full diff to make sure everything is correct:
- Assistant
The diff looks correct. Let me run the full unit test suite to make sure nothing is broken:
- Assistant
The failing tests are in
oxlint-prefer-shared-utils.test.ts, which is unrelated to my changes. Let me verify this is a pre-existing issue: - Assistant
The
oxlint-prefer-shared-utilstest failure is pre-existing and not related to my changes. All the tests related to my change pass. Let me now do a final review of the changes and submit.Let me review the final file to make sure it's clean:
- Assistant
Let me also verify there are no temporary test files left:
- Assistant
Good, no temporary test files remain. Let me now do a final review and submit:
- Assistant
All 139 existing tests pass. Let me now submit the changes.
Let me go through the checklist:
Checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue reported "A self-throwing global error component renders no last-resort UI". I traced through the code and identified that when the global error component itself throws during rendering, the error propagates uncaught without any fallback UI.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.