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 search for global error rendering/fallback paths and relevant tests. Then I’ll reproduce the failure with the narrowest existing test setup, patch the internal error handling without changing public APIs, and run focused plus broader tests.
- Assistant
ripgrepis unavailable, so I’ll usegrep/find. The project is a pnpm TypeScript monorepo; I’ll inspect package scripts and locate the server rendering implementation and tests by filename/content. - Assistant
The likely path is
src/server/app-page-render.tsplus stream recovery and boundary rendering. I’ll inspect those sources, their unit tests, and response/header helpers. I’ll also distinguish generateddistfrom source so the patch follows repository build conventions. - Assistant
The previous output truncated the central lifecycle. I’ll extract the exact recovery function, global rerender decision, final response construction, and focused tests around thrown boundary renders and headers/cookies.
- Assistant
The vulnerability appears in two places: synchronous SSR failure recovery calls the user global boundary and lets a second throw escape; captured RSC errors trigger a later clean rerender that likewise can throw. I’ll inspect both branches and the test factory to reproduce all response metadata expectations, plus signal classification helpers to ensure redirects/not-found remain untouched.
- Assistant
The shell interpreted
!DOCTYPEvia history expansion, so no inspection ran. I’ll rerun with safely quoted patterns. - Assistant
The built-in component itself is React-based, so it cannot serve as a “last resort” after the custom global boundary throws. I’ll inspect its exact markup and response assembly helpers to create an internal static HTML equivalent and merge metadata correctly. I’ll also inspect full option defaults (middleware headers and draft cookie) to determine which headers exist before the boundary response is returned.
- Assistant
A nearby helper already emits a minimal valid HTML fallback for HTTP access errors, but this issue calls for a built-in global-error last resort. I’ll inspect dispatch wiring, special-error HTML, and response builders’ merge order/status behavior. This will clarify whether fallback should be generated at dispatch (where original response headers/cookies are available) rather than generic stream recovery.
- Assistant
The early return of a successful boundary response naturally preserves whatever
renderErrorBoundaryPagebuilds. If that function throws, lifecycle never reaches normal response construction, so middleware headers, edge marker, draft cookie, and content type are lost. I’ll inspect boundary-page rendering to see which metadata is already applied and then add a narrowly scoped last-resort wrapper at the lifecycle level, only around global boundary attempts (not local boundaries or special signals). - Assistant
I’ll verify the boundary response’s canonical status and the request-level catch behavior. Then I’ll implement a private static fallback response builder that uses status 200, generic built-in markup (no exception text/digest), HTML content type, RSC vary, edge/font/middleware headers, and draft cookie. Because draft cookies are currently read later, the builder must read them only on failure and avoid changing normal flow.
- Assistant
There is an earlier failure path (
buildAppPageElement) before lifecycle, so patching lifecycle alone would be incomplete. The common choke point iscreateAppFallbackRenderer().renderErrorBoundary; I’ll inspect it and its tests. A fallback there can cover build, probe, RSC, and SSR errors consistently while leaving local boundary selection and navigation signal handling upstream unchanged. - Assistant
The fallback renderer is the correct scope and already knows middleware headers and edge runtime, but not the draft-mode cookie (which lifecycle owns). Pending cookies may instead already be stored in middleware context or request execution context. I’ll inspect the exact
renderErrorBoundaryimplementation, test harness, and cookie plumbing before editing. - Assistant
The method search missed because it is shorthand without
asyncin the truncated section. I’ll locate it by line number and inspect dispatch options around cookie providers. If the common renderer cannot access draft/pending cookies without a public signature change, I’ll add private factory callbacks (internal interface only) and thread existing providers from the generated entry. - Assistant
Cookie preservation likely means mutable
cookies().set(...), not only draft mode. Since the fallback renderer runs inside request context, it can consume existing internal accessors directly, as special-error paths do. I’ll inspect those accessors and generated import conventions, then build a helper in the fallback renderer that appends pending and draft cookies without exposing the boundary exception. - Assistant
I’ll read the existing global-error tests and then make the smallest source-only change in
app-fallback-renderer.ts. The static fallback should apply only when the resolved boundary is global; if a local error boundary throws, existing propagation must remain unchanged. We can determine that before rendering using the existing boundary resolver rather than catching all failures indiscriminately. - Assistant
I’ll use optional internal cookie-provider callbacks on the renderer factory and wire them from the generated app entry, avoiding unsafe ambient accessor calls in unit-level renderer usage. For local/global classification I’ll call the existing resolver, ensuring page and segment boundaries still rethrow if their own component fails. The last-resort response will merge middleware first, append mutable/draft cookies, force status 200, and never interpolate either the page error or boundary error.
- Assistant
I’m implementing the common renderer fix now. The fallback is intentionally static and generic, includes complete document structure and the built-in global-error message, and uses no error-derived values. It is selected only when the resolver chose the global boundary; local boundary failures continue to reject. Headers and cookies are assembled before request context cleanup.
- Assistant
python3is unavailable, and no files changed. I’ll apply the same deterministic edits with a temporary Node script, remove it immediately, then inspect formatting and type correctness. - Assistant
The source edit applied before the generated-entry needle failed; the displayed indentation is unformatted but structurally likely intact. I’ll fix the entry’s comma-terminated object property, run the formatter on changed files, and inspect the complete method before testing.
- Assistant
The edit itself completed, but
pnpminvoked Corepack’s interactive download and timed out. I’ll use the repository-installedvpbinary directly (if present), avoiding interactive package-manager bootstrap. - Assistant
The common renderer is now wired. I’ll run the focused existing tests and package type/build checks. Since existing tests do not cover a self-throwing global component, after that I’ll create a temporary test outside the repository (or use an inline runner) to reproduce: throwing global component, middleware/custom and Set-Cookie headers, pending/draft cookies, edge marker, 200 status, valid HTML, and absence of the thrown message.
- Assistant
Focused tests and static checks pass. I’ll now run a temporary regression test (deleted immediately afterward) that directly reproduces the reported failure and checks the semantic constraints, including a local boundary that must still reject with its own exception.
- Assistant
The temporary file was correctly removed, but the runner only includes
tests/**, so that reproduction did not execute. Before rerunning it in an included temporary path, I identified an important edge case from the issue wording: if the global boundary throwsredirect()/notFound()itself, the catch must rethrow that control-flow signal rather than convert it to HTML. I’ll add the existing special-error classifier guard, then execute the temporary test undertests/and remove it. - Assistant
The inline Node edit used invalid Python-style triple quotes, so no source change occurred; checks merely reconfirmed the prior state. I’ll use the repository’s literal
replacecommand for the import and catch block, then format/check again. - Assistant
The import applied, but formatting had collapsed imports and the multiline literal replacement no longer matched exactly. I’ll replace the precise displayed line range in the open file, then rerun checks.
- Assistant
The control-flow guard now type-checks. I’ll execute the regression in the configured
tests/include path, including a syntheticNEXT_NOT_FOUNDdigest assertion, and remove the temporary file regardless of result. - Assistant
The reproduction now passes all requested behaviors. I’ll inspect the final diff for accidental formatting churn, run entry-template/code-generation tests because the factory options changed, rerun the focused renderer tests after the signal guard, and build the package to catch generated-entry integration errors. I’ll also check whether build modifies tracked
dist; if so, I’ll follow repository convention based on git status. - Assistant
The diff is narrow: one internal factory enhancement and two generated-entry callbacks. I’ll run the renderer, stream/lifecycle, entry-template, and worker-entry tests plus package build.
- Assistant
The package build completed successfully (only expected unresolved virtual-module warnings) and did not create tracked
distchanges. The unit project ran the three unit-classified files; entry-template files belong to another project, so I’ll run those without forcingunit, then perform final formatting/type checks and inspect status/diff whitespace.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.