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 first map the repository and locate global error rendering/fallback code and its tests. Then I’ll reproduce the self-throwing boundary path, patch the narrow server-rendering behavior, and run the relevant test suites while checking status/header/cookie and control-flow semantics.
- Assistant
The repository is a TypeScript monorepo with focused app-router/error-boundary tests already present. I’ll inspect those tests and search implementation references to
global-error, built-in HTML fallbacks, and render exception handling to identify the exact response construction layer. - Assistant
rgis unavailable, so I’ll use recursivegrep. The boundary unit tests already expose helpers such asrenderAppPageBoundaryResponse, suggesting the bug sits in app page request handling around a second failure. I’ll locate helper definitions and inspect the full error catch path plus response metadata utilities. - Assistant
The implementation performs a normal render, conditionally rerenders with the global boundary, and separately renders explicit boundaries. I’ll inspect these functions end-to-end and the response/header abstractions. The key distinction will be catching only an exception from rendering the selected global boundary, without swallowing navigation signals or changing local boundary behavior.
- Assistant
The stream recovery helper deliberately lets a boundary-render exception escape; that likely reaches a generic server backstop and yields no valid HTML. I need the precise call ownership and metadata state. I’ll print numbered, narrower ranges for
renderAppPageErrorBoundaryand the main HTML recovery sequence, then inspect middleware response header merging (especially repeatedSet-Cookie). - Assistant
The global boundary is identified explicitly (
isGlobalError) before rendering, which gives a safe place to install a last-resort fallback. Next I’ll inspect the return after line 445, the main caller’s special-signal resolution order, and any existing canonical “valid HTML fallback” constant/helper. I’ll also review package scripts to choose a fast focused test command. - Assistant
The shell interpreted
!DOCTYPEas history expansion, so that combined inspection did not run. I’ll rerun it with safe single-quoted patterns and separate the searches. - Assistant
The expected successful fallback status is consistent with existing global-error rendering (
200). In Next-style app rendering, the built-in last-resort document is typically the minimal__next_error__HTML shell. I’ll verify whether this repository already emits or recognizes that marker, and inspect the focused tests’ mocks so I can reproduce the exact lazy-stream failure (which may occur only whenresponse.text()consumes the body, not when theResponseis created). - Assistant
The marker is already used by the built-in global error component and client bootstrap. I’ll inspect that component’s exact markup and styles, plus how stream errors surface in the mocked SSR pipeline. Then I’ll build a temporary reproduction script (not a repository test) invoking
renderAppPageErrorBoundarywith a global component that throws, including middleware cookies/headers. - Assistant
The built-in component establishes the expected marker (
<html id="__next_error__">), and the boundary helper currently passes the original page error into dev SSR metadata. A last-resort response must avoid that path entirely.I’ll check all framework control-flow classifiers rather than treating every digest as a boundary failure. Then I’ll add a private fallback response builder that mirrors normal HTML headers (
Content-Type, RSCVary, edge marker, fontLink, middleware headers andSet-Cookie), returns status 200 with a minimal valid error document, and clears request context. The catch will apply only to HTML rendering of the selected global boundary and will rethrow recognized control-flow signals. - Assistant
There is already a shared
isNextRouterErrorclassifier used by page probing, which is preferable to importing the heavier execution module and preserves redirect/not-found/forbidden/unauthorized semantics. I’ll inspect its exact scope and then implement the minimal fallback. - Assistant
I’ll read the classifier body to ensure it does not overmatch unknown digests, then patch imports and the global-only catch.
- Assistant
isNextRouterErrorcovers the navigation signals named in the issue without swallowing arbitrary digest-bearing exceptions. CSR bailout may also be framework control flow, so I’ll inspectunstable_rethrowclassification and use the repository’s most complete server-control-flow predicate if available. - Assistant
unstable_rethrowis the repository’s complete implemented control-flow classifier: it preserves router signals, CSR bailouts, dynamic-server errors, and wrapped signals while ignoring ordinary exceptions. I’ll use it in the catch. The fallback will intentionally avoid invoking font providers or any user render code, making it genuinely last-resort; it will retain all middleware-produced headers/cookies and framework response headers known without rendering. - Assistant
Python is not installed, so no source changes occurred. I’ll apply the same deterministic edit using Node.js, which is native to this repository, and immediately inspect the diff.
- Assistant
The patch is in place. Before running the permanent suite, I’ll execute a temporary standalone TypeScript reproduction from
/tmpusing the installed Vite module runner if available; this avoids touching repository tests. The reproduction will force the global component to throw synchronously during boundary serialization and assert status, exact valid HTML, headers, cookie, context cleanup, and absence of both secret error messages. - Assistant
Only
vpis exposed, so I’ll use the focused existing boundary tests first. These cover successful local/global boundaries and middleware metadata, guarding regressions. Then I’ll run type/lint checks; if needed, I can use Vite Plus’s explicit file execution facilities for a temporary reproduction. - Assistant
The shell does not include
node_modules/.binonPATH; the binary is present. I’ll rerun via its explicit path. - Assistant
The focused suite passes (88 tests), but it does not include the reported self-throw. I’ll now create a temporary test under
/tmpand ask Vite Plus to execute that explicit absolute path. It will model the same synchronous component render used by the repository’s helper tests and assert the complete issue contract. The file remains outside the repository and will be deleted afterward. - Assistant
Vite Plus enforces configured include globs and therefore rejected the external
/tmpfile without executing it. To genuinely reproduce and verify while honoring the no-test-change rule, I’ll use a transient script file in the configuredscripts/**location, remove it immediately after each run, and confirmgit statusafterward. I’ll run it once against the fix, then save the patch, restore the original source, run the same reproduction to observe the failure, and reapply the patch. - Assistant
The fixed reproduction passes all assertions, and the transient file is gone. I’ll now validate the pre-fix behavior with a smaller transient reproduction that expects the global boundary call to resolve to a response. I’ll temporarily restore the source from Git, observe that this assertion fails with
boundary-secret, then restore the exact patch and clean up. - Assistant
The pre-fix reproduction failed exactly as reported by exposing the boundary exception (
Error: boundary-secret) instead of returning a response; the patch was then restored and no temporary files remain. Next I’ll run formatter and lint/type checks on the changed source. I’ll also exercise control-flow and local-boundary behavior with transient assertions if static checks pass. - Assistant
Formatting and lint both pass. I’ll now run a transient semantic test covering the edge cases called out in the issue: a self-throwing local boundary must still reject, a global boundary throwing
redirect()must propagate the exact navigation signal, and an RSC global-boundary failure must retain its existing rejection rather than returning HTML. This confirms the catch is intentionally narrow. - Assistant
All three narrow-semantics assertions pass, and the transient file is removed. I’ll run the repository checker on the changed file and then build the
vinextpackage to catch TypeScript/module graph issues that unit transpilation may miss. Finally I’ll rerun the focused tests after the temporary source restore/reapply cycle and inspect the final diff/status. - Assistant
The changed file passes formatting, lint, and type checking; the package build succeeds (its known virtual-module warnings are non-fatal). Since the build regenerates tracked-looking
distartifacts, I’ll inspect status and revert generated outputs if Git reports them—source-only changes are the repository convention unless the diff already tracked generated changes. Then I’ll rerun the focused tests once more and review the final patch. - Assistant
The final focused suite again passes all 88 tests, and only the intended source file is modified. One subtle ordering improvement remains: normal response construction snapshots middleware headers before deferred context cleanup. I’ll mirror that order in the fallback—merge headers/cookies first, then clear context—so cleanup cannot affect response metadata in alternate runtime implementations. Then I’ll perform the final diff review.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.