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 structure to understand the codebase and then identify the issue.
Assistant
Let me explore the repository structure more to understand what kind of project this is. It seems to be a Next.js-like framework called "vinext". Let me look for error-related files.
Assistant
Let me search for error-related files, especially global error components and error boundaries.
Assistant
Let me look for source files specifically, not just dist files. I should focus on the packages/vinext/src directory.
Assistant
Let me look at key files related to the global error handling:
Assistant
The file references
DefaultGlobalErrorfrom "vinext/shims/default-global-error". Let me look at that file.Assistant
Now let me look for the error boundary rendering logic, particularly how the global error component is rendered and what happens when it throws:
Assistant
Now let me look at the boundary render file and the app-page-render file:
Assistant
Now let me search for where the global error rendering is handled and how errors are caught:
Assistant
Let me look at the tests to understand the expected behavior:
Assistant
Let me look at the error-boundary test file:
Assistant
Now let me search for tests specifically related to self-throwing global error or fallback UI:
Assistant
Let me look at the global-error test:
Assistant
Now let me look at the app-page-stream file to understand how the HTML response is created and where errors are handled:
Assistant
Now let me look at the app-page-render.ts file to understand the full flow:
Assistant
Let me look for where the RSC rendering happens and where errors during that rendering might be caught:
Assistant
Let me search for how errors during global error rendering are handled:
Assistant
Let me look at how the RSC handler renders the error boundary response and whether it handles errors when the global error component itself throws:
Assistant
Now let me look at the test file for app-fallback-renderer to understand the test scenarios better:
Assistant
Now let me search for tests or code related to the "self-throwing" global error behavior, which is when the global error component itself fails:
Assistant
Let me search more specifically for where the global error component rendering could fail:
Assistant
Let me look at the relevant issue. When the global error component itself throws, what happens? Let me look at
renderAppPageErrorBoundarymore carefully, and specifically the rendering pipeline:Assistant
Now let me look at the
renderAppPageBoundaryElementResponsemore closely and see how errors in rendering the boundary response itself are handled:Assistant
Let me understand the full flow better by looking at the
renderAppPageBoundaryResponsefunction inapp-page-boundary.ts:Assistant
Now I understand the flow. When the global error component itself throws, the error bubbles up through the
renderToReadableStreamcall and is not caught. The issue is asking that when the global error component fails, we should return a built-in HTML fallback with a successful status (500), while preserving response headers and cookies.Let me look at how Next.js handles this scenario and find where in vinext's code we need to add this fallback:
Assistant
Let me look at
renderAppPageErrorBoundarymore carefully to see what happens when the global error boundary renders and throws:Assistant
Now I understand the issue. When
renderAppPageErrorBoundaryis called and the resolved error boundary IS the global error (e.g.,errorBoundary.isGlobalErroris true), if the global error component itself throws during rendering, there's no fallback. The error just propagates up.The issue says: "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."
Let me check what happens in
renderAppPageBoundaryElementResponsewhen an error occurs:Assistant
Let me check where errors during error boundary rendering can happen in the whole flow. Let me look at where
renderAppPageErrorBoundaryis called:Assistant
Let me look at the AGENTS.md file to understand what's expected:
Assistant
Let me continue reading the AGENTS.md to look for more context on the issue:
Assistant
Let me look at how the existing codebase handles error rendering when
renderAppPageBoundaryElementResponseis called:Assistant
Assistant
Let me check the git log to see if there were recent changes related to global error handling:
Assistant
Let me look at the existing tests to understand the expected behavior and see if there's a test related to this specific issue:
Assistant
Let me search the Next.js reference for how they handle self-throwing global errors:
Assistant
Let me look at the pages-page-handler.ts to see how it handles self-throwing error pages:
Assistant
Now I can see the pattern! The Pages Router already handles the case when an error page itself throws by using an
__isInternalErrorRenderflag. Let me see how it's used:Assistant
Now I understand the pattern. For the Pages Router, when the error page itself fails, it returns a plain text "Internal Server Error" response. Let me now look at the App Router side and find where a similar fix needs to be applied.
The issue is in
renderAppPageErrorBoundary- when the global error component itself throws during rendering, the error should be caught and a built-in HTML fallback should be returned.Let me examine the flow more carefully:
Assistant
Now I understand the codebase structure. The issue is about handling the case when the global error component itself throws. In this case, there should be a built-in HTML fallback rendered with:
- Status 500
- Preserved response headers and cookies
- A valid HTML fallback UI
- The original boundary exception should not be exposed
- Local error boundaries and framework navigation/control-flow signals should retain their semantics
The key place to handle this is in
renderAppPageBoundaryResponseinapp-page-boundary.ts. When therenderToReadableStreamcall fails during a global error render, we need to catch that error and return a simple HTML fallback.Let me also check how the dev-server handles a similar case:
Assistant
Now let me look at the default global error component to understand what a simple built-in fallback HTML should look like:
Assistant
Now I have a good understanding. Let me create a reproduction script and test to confirm the issue, then fix it.
Let me first write a test to understand and reproduce the issue:
Assistant
Let me try a different approach - use npx vitest directly:
Assistant
The tests are taking too long. Let me just proceed with implementing the fix based on my understanding, and then verify it works.
Based on my analysis, the fix needs to be in
renderAppPageBoundaryResponseinapp-page-boundary.ts. When therenderToReadableStreamcall fails (because the global error component throws), we should:- Catch the error
- Return a built-in valid HTML fallback with status 500
- Preserve response headers and cookies
- Not expose the original boundary exception
Let me also look at where the RSC request path handles errors:
Assistant
Now let me look at the
renderAppPageBoundaryElementResponseto understand how it callsrenderAppPageBoundaryResponse:Assistant
Let me now implement the fix. The key change is in
renderAppPageBoundaryResponseinapp-page-boundary.ts. When rendering fails (which happens when the global error component throws), we need to catch the error and return a simple HTML fallback.Assistant
Now I understand the structure. The issue is that when the global error component itself throws, the error propagates up through
renderToReadableStreamand the error is not caught.Looking at the code flow:
renderAppPageErrorBoundaryinapp-page-boundary-render.tsresolves the error boundary- If it's the global error, it calls
renderAppPageBoundaryElementResponse - That calls
renderAppPageBoundaryResponseinapp-page-boundary.ts - If the global error component throws, the error bubbles up
The fix should be in
renderAppPageBoundaryResponse- we need to catch errors fromrenderToReadableStreamandcreateHtmlResponse, and when they fail, return a simple HTML fallback.Let me implement the fix:
Assistant
command_str
Assistant
The changes look good. Now let me verify the file is correct by checking the full content:
Assistant
The changes look good. Now let me verify that TypeScript compiles correctly:
Assistant
TypeScript compiles successfully. Now let me also check if there's any issue with the
renderToReadableStreamcall itself — the current code only wraps thecreateHtmlResponsecall in a try/catch, but the error could also occur during therenderToReadableStreamcall itself (when the element is rendered to a stream). Let me check if errors duringrenderToReadableStreamwould be synchronous or asynchronous:Assistant
...
Assistant
I see that
renderToReadableStreamusesonErrorcallback to handle errors during streaming, and it doesn't throw synchronously — the errors flow through the stream. However, the actualcreateHtmlResponsecall inrenderAppPageBoundaryElementResponseis where the SSR handler processes the RSC stream and generates HTML. If the global error component throws during SSR, the error would occur insiderenderAppPageHtmlStreamorhandleSsr.Let me look at how the RSC rendering works for error boundaries to understand better:
Assistant
The
createHtmlResponseis an async function that callsrenderAppPageHtmlResponse, which in turn callsrenderAppPageHtmlStream. When the global error component throws during RSC rendering, the error might be captured by the RSConErrorhandler but the stream might still be produced. However, if the component throws during SSR (when the stream is consumed), the error would propagate throughrenderAppPageHtmlStream.Let me also check if there's a case where
renderToReadableStreamcould throw synchronously:Assistant
The
runWithFetchDedupeis synchronous (it callsfn()synchronously). So ifrenderToReadableStreamthrows synchronously, it would bubble up. However,renderToReadableStreamfromreact-dom/server.edgetypically doesn't throw synchronously — it creates a stream and errors are reported via theonErrorcallback.But wait, looking at the issue more carefully, the
createHtmlResponsefunction also callsrenderAppPageHtmlResponsewhich internally callsrenderAppPageHtmlStream. If the error component throws during SSR (when consuming the RSC stream), the error would propagate through the promise chain.The current fix catches errors from
createHtmlResponse, which should cover the SSR path. Let me also wrap therunWithFetchDedupecall in a try/catch to handle any synchronous errors during RSC rendering:Assistant
Let me verify TypeScript compiles correctly:
Assistant
Now let me check if the existing tests pass. Let me first look at the related test files to understand what tests exist:
Assistant
Good, I can see the existing tests. Let me run them to make sure my changes don't break anything:
Assistant
Let me try using a different approach:
Assistant
All 10 tests pass. Let me also run the related test files:
Assistant
Let me also run the app-fallback-renderer tests:
Assistant
All tests pass. Now let me clean up the test file I created earlier and run the global-error related tests:
Assistant
Excellent! All 22 global-error tests pass. Let me now run a broader set of tests to make sure the changes don't break anything else:
Assistant
Let me also run the error-related tests:
Assistant
All tests pass. Let me now verify my changes by reviewing the final file content:
Assistant
Let me verify everything looks good and run a few more tests to confirm the fix doesn't break anything:
Assistant
The previous command succeeded and there's no error. Let me continue with more tests to verify the fix.
Assistant
All tests are passing. Let me now check if there are any other tests related to error handling that I should run to make sure the fix is complete.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.