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
Now let's look at
applyEdgeRuntimeHeader:Assistant
Now let's update
renderAppPageErrorBoundaryto use this fallback when the global error boundary itself throws.Assistant
Now let's update the tail of
renderAppPageErrorBoundaryto wrap the render call in try/catch.Assistant
Looks fine; let's just use
editwith explicit line range instead.Assistant
No errors. Let's check the vp check / lint scripts referenced at root for a proper type check across the repo.
Assistant
Good, it did run against that tsconfig with no errors. Now let's write a small reproduction test to confirm the fix using the existing test infrastructure (app-fallback-renderer.test.ts style), without permanently modifying test files.
Assistant
Now let's look at the "global-error boundaries" test and
createCommonOptions/createMiddlewareContexthelpers for constructing a temp reproduction script.Assistant
The test passes, confirming the fix works. Now let's verify the pre-fix behavior would have failed (i.e., without the fix the test would throw). Let's temporarily revert and check.
Assistant
Confirmed the bug reproduces without the fix, and the fix resolves it. Let's restore the fix.
Assistant
Now let's also verify special-error and local-boundary preservation behave as intended with additional quick checks in the temp test file, then remove it before final submission.
Assistant
All three scenarios behave as intended. Now let's remove the temp test file and run the broader existing test suites related to this area to make sure nothing broke.
Assistant
So
entry-templates.test.tsandnextjs-compat/global-error.test.tsare part of the integration project. Let's run those (may take longer).Assistant
Now let's run the nextjs-compat global-error test (integration project) which does a full dev server run — this is a good end-to-end sanity check.
Assistant
All 22 pre-existing tests pass. Now let's run the broader unit test project fully to make sure nothing else broke.
Assistant
All unit tests pass (5870 passed, 2 skipped — pre-existing skips unrelated to our change). Let's also quickly run the integration project fully to be thorough, though it may take a while.
Assistant
Both pass. Let's also verify the type-check/lint for the whole vinext package once more (full check) to be safe.
Assistant
Now let's review the diff one more time for sanity.
Assistant
This looks correct. Let's also double check the new file content once more.
Assistant
Good, structurally valid. Let's remove this temp test file now.
Assistant
Good, this confirms the pattern: synchronously-built (non-streamed) fallback responses call
clearRequestContext()immediately. Let's add this to our last-resort path too.Assistant
Let's also re-verify the reproduction scenarios once more end-to-end with the added
clearRequestContextcall, using a fresh temp test, then delete it.Assistant
Headers, cookies, and context clearing all confirmed. Let's clean up temp files.
Assistant
Now let's run the full unit test suite once more (final confirmation) and the targeted integration tests.
Assistant
All unit tests pass. Let's re-run the nextjs-compat/global-error integration test once more to make sure the additional
clearRequestContext()call didn't regress anything there.Assistant
All tests pass. Let's do a final review of the complete diff.
Assistant
This looks complete and correct. Let's go through the checklist.
Assistant
Summary
I resolved the issue by adding a guaranteed-safe "last resort" fallback for the App Router's global error boundary rendering path.
Root cause:
renderAppPageErrorBoundary(inapp-page-boundary-render.ts) selects a boundary component (a localerror.tsx, or — when none exists —app/global-error.tsx/vinext's built-in default) and renders it. If that selected component itself throws while rendering (a bug in the user'sglobal-error.tsx, for instance), the exception propagated all the way up throughrenderAppPageHtmlStreamWithRecovery→renderAppPageLifecycle→ the RSC handler, uncaught — producing no usable response ("no last-resort UI").Fix:
- Added
packages/vinext/src/server/app-page-last-resort-fallback.ts: a self-contained, static (non-React) HTML string mirroring the built-inDefaultGlobalErrorUI ("This page couldn't load" / "A server error occurred. Reload to try again."), plusbuildAppPageLastResortResponse()which wraps it in aResponsewith status200, merging in any existing middleware headers/cookies via the samemergeMiddlewareResponseHeadershelper used elsewhere. Being pure string content, this can never throw itself. - Wrapped the render call in
renderAppPageErrorBoundaryin atry/catch:- If the caught error carries a
digest(redirect/notFound/forbidden/unauthorized signal fromresolveAppPageSpecialError), it's rethrown unchanged — framework navigation/control-flow semantics are preserved. - If the boundary that failed was a local
error.tsx(!errorBoundary.isGlobalError), it's rethrown unchanged — local error boundary behavior is untouched/out of scope. - Otherwise (the global error boundary itself failed), it logs both the original and the boundary's own exception server-side only (never exposed to the client) and returns the static last-resort
Response, also synchronously clearing per-request context since this response bypasses the normal streaming path.
- If the caught error carries a
Verification: Wrote and ran temporary reproduction tests (removed before submitting) proving: (a) a self-throwing global-error now yields a 200 HTML fallback without leaking either exception's message, (b) a self-throwing local
error.tsxstill propagates unchanged, (c) a digest-bearing signal thrown from the global boundary still propagates unchanged, and (d) headers/cookies frommiddlewareContextare preserved andclearRequestContextis invoked. Ran the full unit suite (5870 passed, 2 pre-existing skips) plus targeted integration suites (nextjs-compat/global-error.test.ts,entry-templates.test.ts,app-router-dev-server.test.ts,app-router-production-server.test.ts) — all green.tsc --noEmiton the vinext package is clean.- Added
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 →
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 →