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 to understand what we're working with.
Assistant
This appears to be the Vinext repository - a Next.js-like framework. Let me explore the packages and the structure more.
Assistant
Let me search for "global-error" related code, which is the issue here. The issue is about a self-throwing global error component rendering no last-resort UI.
Assistant
This is the key file. Let me look at the error boundary rendering. The issue is: when the global error component itself fails (self-throwing), we need to 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.
Let me look at how the error boundary rendering handles the global error. The
renderAppPageErrorBoundaryfunction renders the global error component. When the global error component itself throws during render (RSC render or SSR render), we need to catch that and return the built-in fallback HTML.Let me look at the
app-rsc-error-handler.tsandapp-rsc-errors.tsfiles.Assistant
Now let me look at the
app-page-boundary.tsto understandrenderAppPageBoundaryResponse,resolveAppPageErrorBoundary,wrapAppPageBoundaryElement.Assistant
Now let me understand the rendering pipeline. The key issue: when the global error component itself throws during render, what happens? Let me look at how the error boundary response is rendered and where errors during render would surface. Let me look at
app-page-stream.tsforrenderAppPageHtmlResponse.Assistant
Now let me look at the main render dispatch where errors trigger rendering of the error boundary. Let me look at
app-page-render.ts.Assistant
Let me see the full middle part of the file to understand the lifecycle and where renderErrorBoundaryResponse is set up.
Assistant
Now let me understand the dispatch layer that calls
renderErrorBoundaryResponse/renderAppPageErrorBoundary. Let me look atapp-page-dispatch.ts.Assistant
Now let me find where
renderErrorBoundaryPageis wired tocreateAppFallbackRenderer().renderErrorBoundary. Let me search.Assistant
Now I understand the flow. Let me look at the test directory to understand what's expected for this issue.
Assistant
Let me look at the test file to understand existing tests for global error rendering and the structure they use.
Assistant
Now let me understand the issue better. Let me look at the default global error module and shim.
Assistant
Now I understand. Let me look at the http-error-responses.ts file - perhaps there's a static HTML fallback for errors.
Assistant
Now let me look at the dispatch flow. Let me look at
app-page-dispatch.tsin full.Assistant
Let me check the .nextjs-ref to understand Next.js's behavior for this case.
Assistant
Let me look at the existing tests for
app-fallback-rendererto understand the test setup and expectations.Assistant
Let me write a reproduction test to confirm the issue.
Assistant
I've reproduced the issue. Now let me understand the production SSR handler to know whether the error happens before or after the response is sent.
Assistant
Let me check the changeset directory and any hints about this issue.
Assistant
Let me look at how Next.js reference is stored, and check the app-page-render.ts full lifecycle to understand the recovery for the error boundary render.
Assistant
Let me search for any existing static HTML fallback for errors and look at how the default global error is used elsewhere.
Assistant
Let me look at the
app-page-element-builder.tsto understand the global error usage pattern there.Assistant
Let me look at how
renderToReadableStreamis defined in the RSC entry (production).Assistant
Let me look at the existing
app-page-render.test.tsfor global error recovery tests to understand the test harness.Assistant
Let me look at the
createCommonOptionsin app-page-render.test.ts to understandrenderErrorBoundaryResponse.Assistant
Let me check how
global-error.tsxis treated (client vs server component) in the build/routing.Assistant
Let me look at the nextjs-compat test for global-error to understand the expected behavior.
Assistant
Let me check how the fallback renderer's
ssrLoaderandrscRendererare wired in the app-rsc-entry.Assistant
Let me look at the test helpers to understand how to start a fixture server.
Assistant
Let me create a fixture app for self-throwing global error to observe the real behavior. First, let me look at the existing app-basic fixture structure.
Assistant
Let me search for tests that use
renderAppPageErrorBoundaryto ensure buffering won't break them.Assistant
Let me look at the remaining tests in this file (540-620).
Assistant
Let me look at the app-fallback-renderer test for renderErrorBoundary.
Assistant
Now I understand the structure well. Let me create a fixture app to observe the real production/dev behavior of a self-throwing global error component.
Assistant
Let me see the full output including the HTML body.
Assistant
Interesting — in dev the self-throw surfaces as a 500 synchronously. Let me check what
renderToReadableStreamis in the SSR entry.Assistant
Let me test whether
renderToReadableStreamfromreact-dom/server.edgethrows synchronously on a shell error.Assistant
renderToReadableStreamthrows synchronously on shell errors. So a try/catch around the render inrenderAppPageErrorBoundarywill catch the self-throw even in production. Let me implement the fix. Let me view the exact lines ofrenderAppPageErrorBoundary.Assistant
Now let me implement the fix. First let me check the existing imports in the file.
Assistant
Let me check how
mergeMiddlewareResponseHeadersworks to preserve headers and cookies in the static fallback.Assistant
Now let me look at how the html response sets headers (Vary, Content-Type, edge runtime, font link header, middleware headers). Let me check
applyEdgeRuntimeHeaderand theVINEXT_RSC_VARY_HEADER.Assistant
Now let me implement the fix. First, let me check current imports and the
applyEdgeRuntimeHeader/VINEXT_RSC_VARY_HEADERavailability.Assistant
Now let me add the necessary imports and implement the fix.
Assistant
Now let me add the imports:
Assistant
Now let me modify the
renderAppPageErrorBoundaryfunction to wrap the render and add the fallback logic.Assistant
Now let me modify the final render block to add the try/catch and fallback.
Assistant
Let me navigate to the area and use line-range editing.
Assistant
Now let me edit the return block to add the try/catch and fallback helpers.
Assistant
Let me view the rest of the added code to verify correctness.
Assistant
Now let me run my reproduction unit test to verify the fix.
Assistant
The unit test passes — status 200 with the built-in default global error UI. Now let me run the integration test (dev server) to confirm the production/dev case.
Assistant
The dev server case now returns 200 with the built-in UI. Let me verify the original error messages are NOT exposed in the response body.
Assistant
Let me see which assertion failed and the actual HTML content.
Assistant
The integration test reveals the original error message leaks via the embedded RSC flight payload in dev. I need to pass a generic (production-sanitized) error to the fallback so the original exception isn't exposed. Let me import
sanitizeErrorForClientand update the fallback.Assistant
Now let me update the fallback function to use a production-sanitized error so the original exception isn't exposed. Let me view the current call site and function.
Assistant
Let me update the function. I'll change the
errorObjectparameter to compute a production-sanitized fallback error fromoptions.error. Let me replace the function signature and the element creation.Actually, let me change the call site to not pass
errorObject, and inside the function computefallbackError. Let me edit.First, change the call site:
return renderAppPageGlobalErrorFallback(options, pathname);(remove errorObject).Then change the function signature to
(options, pathname)and computefallbackError.Assistant
There's a duplicate closing paren at line 522. Let me remove it.
Assistant
Let me check for potential circular imports introduced by the new value imports.
Assistant
Now let me run the integration test again to confirm no leak of the original exception.
Assistant
The integration test passes — no leak. Now let me run the existing tests for the affected files to ensure nothing broke.
Assistant
All pass. Let me run a broader set of related tests to ensure nothing broke.
Assistant
Let me write a comprehensive temporary test covering edge cases: middleware headers/cookies preservation, RSC path, and local-boundary propagation.
Assistant
Let me test the static fallback path (when even the built-in default throws).
Assistant
The static fallback works correctly (the test assertion just mismatched the apostrophe entity encoding). Let me run the existing nextjs-compat global-error test suite to ensure my change doesn't break the normal (non-self-throwing) behavior.
Assistant
All 22 global-error compat tests pass. Let me check whether
distis gitignored (build artifacts) and whether I need to rebuild it.Assistant
dist/is gitignored. Let me check whether any tests import the affected code fromdistvssrc.Assistant
Let me rebuild vinext's dist to keep it consistent with src (in case any path uses dist).
Assistant
Build completed. Let me verify the dist contains my changes.
Assistant
Wait, line 268 says
return renderAppPageGlobalErrorFallback(options, errorObject, pathname);but I changed the call site torenderAppPageGlobalErrorFallback(options, pathname). The dist seems stale for that line. Let me check the dist more carefully — maybe the build didn't pick up the latest src (cache). Let me check the dist's call site and function signature.Assistant
The dist's call site still passes
errorObject(3 args) but the function takes 2 args. Let me check the current src call site.Assistant
The call site still passes
errorObject— my earlier replace failed. Let me fix it now.Assistant
Now the call site matches. Let me re-run the edge and integration tests to confirm everything works.
Assistant
All pass. Let me rebuild dist to reflect the corrected call site, then verify.
Assistant
Now the dist is consistent. Let me run a broader set of related unit tests to ensure nothing broke.
Assistant
The fix is complete and consistent. Let me clean up all temporary test files and the scratch fixture.
Assistant
Clean — only the source file is modified. Let me do a final review of the full diff.
Assistant
Let me reconsider the
layoutModulespassed in the fallback. To make the fallback indistinguishable from a normal global error render (same payload structure), I should pass the samelayoutModulesthe normal path uses. Let me update the fallback.Assistant
Let me update the fallback to compute
layoutModulesmatching the normal global error render. ThewrapRenderedBoundaryElementignores layoutModules when skipLayoutWrapping, so I can pass the route layouts there too (for consistency, though it's ignored). And pass the same torenderAppPageBoundaryElementResponse.Let me edit. I'll add
const layoutModules = options.route?.layouts ?? options.rootLayouts;aftermatchedParams, and use it in both places.Assistant
Let me replace both
layoutModules: []withlayoutModulesto match the normal global error render.Assistant
Let me re-run the affected unit tests to confirm everything still works.
Assistant
Let me re-create the integration fixture + test once more to verify end-to-end after the layoutModules change, then clean up.
Assistant
Let me inspect the actual HTML to see which variant rendered.
Assistant
Let me get the full rendered body to understand which variant and where text appears.
Assistant
The visible text shows the client variant, meaning the
digestis lost in the RSC round-trip. Let me check the embedded RSC payload to understand.Assistant
The RSC payload serializes the error with
name,message,stackbut NOdigest. Let me check React's flight error serialization to understand why digest is dropped.Assistant
Let me find the flight serializer used by vinext's RSC plugin to see how errors are serialized.
Assistant
The visible text shows the client variant renders in real SSR (React's flight serializer drops
digestfor prop-passed errors — a pre-existing characteristic of the default global error component). This is valid HTML, status 200, no original exposure. My earlier verify-test assertion was overly strict. Let me clean up the dump tests and run a final clean verification with correct assertions.Assistant
All final assertions pass. Let me clean up the temp test/fixture and rebuild dist to reflect the latest source.
Assistant
Dist is consistent. Let me run a broad sweep of the unit test suite to ensure nothing broke.
Assistant
All 5870 unit tests pass. Let me run the related integration compat tests (global-not-found, not-found) to ensure the fallback renderer changes don't break them.
Assistant
All pass. Let me do a final review of the complete modified region.
Assistant
The code looks clean. Let me run a typecheck/lint on the changed file to ensure no type or lint errors.
Assistant
Let me fix the formatting issue and review the result.
Assistant
vp check --fixpassed with no warnings/lint/type errors. Let me verify the static fallback HTML string is still intact after formatting.Assistant
The HTML string is intact (just reflowed). Let me rebuild dist (formatting changed the source) and re-run the affected unit tests to confirm.
Assistant
All tests pass. Let me do a final review of the git status and diff summary.
Assistant
The fix is complete and verified. Let me do a final confirmation that only the intended source file is modified and the dist is consistent.
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 →