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 start by exploring the repository structure to understand what we're working with.
Assistant
This appears to be a Vite-related project, likely "vinxi" or "vinct" or similar. Let me explore more.
Assistant
This is a Next.js-like framework. Let me look at the server directory since the issue is about global error components and error handling.
Assistant
Let me search for relevant files related to global error handling.
Assistant
Now let me look at the boundary render file, which seems to be the core of the error boundary logic.
Assistant
Let me look at the default global error module and the shims.
Assistant
Let me look at the boundary response rendering and the stream rendering.
Assistant
Let me look at the HTML response rendering in the stream file.
Assistant
Let me search for where the recovery and global error rerender is used.
Assistant
Let me look at the dispatch file to see how
renderErrorBoundaryResponseis wired.Assistant
Let me look at the SSR stream handler.
Assistant
Let me look at the SSR entry to understand how SSR handles errors during rendering.
Assistant
Let me look at the tests directory to understand the testing setup and find relevant tests.
Assistant
Let me look at the existing boundary render tests and the fallback renderer tests.
Assistant
Let me search for any existing fallback HTML or static HTML handling.
Assistant
Let me look at the http-error-responses.ts to understand static HTML fallbacks.
Assistant
Let me look at the app-page-render.ts structure more broadly.
Assistant
Let me look at app-page-request.ts to understand the request flow.
Assistant
Let me look at the sanitizer and digest logic.
Assistant
Let me look at how the fallback renderer is created in the entry and how the sanitizer is wired.
Assistant
Let me look at
resolveAppPageSpecialErrorand the special error types.Assistant
Let me check if there's a Next.js reference in the repo to understand the expected fallback behavior.
Assistant
Let me look at the global-error compat test file.
Assistant
Let me look at the existing global-error fixture and the app-basic fixture's global-error.tsx.
Assistant
Let me look at the test helpers and how the dev server is started.
Assistant
Let me look at the app-basic fixture structure and create a reproduction.
Assistant
Let me create a reproduction script using the boundary render function directly.
Assistant
Let me create the reproduction inside the repo so it can resolve packages, using the test framework.
Assistant
Let me rewrite the reproduction using the existing test harness approach.
Assistant
I've reproduced the issue. Now let me check what's available for rendering static HTML in the boundary render module.
Assistant
I've reproduced the issue. Now let me check for potential circular dependencies before implementing.
Assistant
app-page-execution.tsdoesn't importapp-page-boundary-render.ts, so no circular dependency.app-page-boundary-render.tsis only imported byapp-fallback-renderer.ts. Andapp-page-execution.tsdoesn't import either. Let me verifyapp-page-execution.tsisn't imported byapp-page-boundary-render.tsalready (it's not, based on the imports I saw). Let me double-check the full imports ofapp-page-boundary-render.ts.Assistant
app-page-boundary-render.tsalready imports from./app-page-execution.js(type only). Let me check thedefault-global-error-module.tsexport and theAppPageSpecialErrortype.Assistant
Let me verify the
vinext/shims/default-global-errorimport resolves in the test environment by checking the existing fallback renderer test.Assistant
So the
app-fallback-renderer.test.tsusesglobalErrorModule: null, which means it falls back toDEFAULT_GLOBAL_ERROR_MODULE. So the import chaindefault-global-error-module.ts->vinext/shims/default-global-errorworks in the test environment.Let me find a test in
app-fallback-renderer.test.tsthat exercises the default global error to confirm.Assistant
Now I understand the test patterns. The default global error component renders "This page couldn't load" etc. When
errorhas no digest, it's the client error variant; with digest, server error variant.Now, let me think about the fallback. When the user's global error component throws, I fall back to the default global error component. I'll pass
error: nullso it renders the client error variant (no digest, "Reload to try again, or go back", with Back button). This doesn't expose the original exception.Wait, but actually, I want to reconsider. Looking at the existing test "renders the built-in default global error UI for client errors", when
erroris passed without digest, it shows the client variant. When the user's global error throws, this IS effectively a server error (the component threw on the server). But since we don't want to expose anything, passing null (client variant) is appropriate, OR we could pass a generic error without a message.Actually, hmm. Let me reconsider whether passing null is right. The default global error component's client variant shows "Reload to try again, or go back." with a Back button. The server variant shows "A server error occurred. Reload to try again." with no Back button and an "ERROR " footer.
Assistant
Let me now implement the fix. First, let me look at the exact lines in
renderAppPageErrorBoundaryto modify.Assistant
Now let me implement the fix. I'll add the import for
DEFAULT_GLOBAL_ERROR_MODULEand a last-resort fallback helper, then wrap the final response rendering in try/catch.Assistant
Now let me add the import for
DEFAULT_GLOBAL_ERROR_MODULE:Assistant
Let me check the
default-global-error-module.tsfor circular imports.Assistant
default-global-error-module.tsonly imports fromvinext/shims/default-global-error, which is a separate shim module - no circular dependency withapp-page-boundary-render.ts.Now let me add the import and implement the last-resort fallback.
Assistant
Now let me add the last-resort fallback helper function. Let me place it right before
renderAppPageErrorBoundary:Assistant
Now let me view the full
renderAppPageErrorBoundaryfunction and replace it with the try/catch version that falls back to the default global error component.Assistant
Now I'll add the last-resort fallback helper before the
renderAppPageErrorBoundaryfunction and wrap the final response in try/catch. Let me first add the helper function:Assistant
Now let me insert this helper before the
renderAppPageErrorBoundaryfunction. Let me find the exact line and use theopen/editapproach.Assistant
Now I'll insert the helper function before
renderAppPageErrorBoundary(line 380):Assistant
There's an extra
}at line 379. My edit duplicated a closing brace. Let me fix that:Assistant
Now let me update the
renderAppPageErrorBoundaryfunction body to wrap the finalrenderAppPageBoundaryElementResponsecall in try/catch. Let me view the current state:Assistant
Now let me replace the final return block with a try/catch:
Assistant
Now let me run my reproduction test to verify the fix:
Assistant
The fix works. The response now returns 200 with the built-in default global error UI. Now let me enhance my reproduction test to verify all the requirements: middleware headers preserved, original error not exposed, etc.
Assistant
All assertions pass: status 200, built-in UI, no exposure of original error or self-throw message, no digest footer, and middleware headers/cookies preserved.
Now let me verify that the existing tests for the boundary render still pass.
Assistant
Let me run a broader set of related tests to ensure nothing breaks.
Assistant
Now let me also consider the RSC request path. When
isRscRequestis true, the boundary response is an RSC response, not HTML. The issue says "renders no last-resort UI", which is about HTML. But for completeness, let me think about whether the RSC path also needs handling.When
isRscRequestis true and the global error component throws during RSC render, therenderAppPageBoundaryElementResponsewould throw. My catch handles that and callsrenderAppPageGlobalErrorLastResortFallbackwhich usesoptions.isRscRequest. For RSC requests, it would render an RSC response with the default global error component. That's the correct behavior — the RSC payload would contain the default global error component.Let me verify the RSC path works with a test:
Assistant
Both HTML and RSC paths work. Now let me clean up my temporary reproduction tests.
Assistant
Only the source file is modified. Let me review the final diff:
Assistant
Now let me consider an important edge case: what if the default global error component ALSO throws? This would cause an infinite loop or unhandled rejection. Let me check the default global error component - it's a simple static component that shouldn't throw. But to be safe, the fallback itself could throw. Let me think about whether I should add a second-level fallback.
The default global error component (
DefaultGlobalError) is a pure, static component with no logic that could throw — it only readserror?.digest. So passingerror: nullmakes it render the client variant safely. There's no realistic way for it to throw.However, there's a theoretical risk: if
renderAppPageBoundaryElementResponseitself fails for an infrastructure reason (e.g., SSR handler throws, font providers throw) when rendering the fallback. In that case, the exception would propagate up. But that's acceptable — the issue is specifically about the global error component self-throwing, and we've handled that. The fallback uses the same rendering pipeline, so if the pipeline itself is broken, there's nothing more we can do at this layer.Let me now run the error-boundary test and a few more related tests to be thorough.
Assistant
Let me run a type check to make sure the TypeScript compiles cleanly.
Assistant
These errors are all pre-existing (in
apps/web,tests/, and one inindex.tsaboutNODE_ENV) — none are related to my change. Let me confirm there are no errors inapp-page-boundary-render.ts:Assistant
No errors in my modified file. Let me confirm the pre-existing errors exist on the original version by checking git stash:
Assistant
Same error count (22) before and after my change, confirming I introduced no new TypeScript errors.
Now let me run the lint check on the modified file to ensure formatting is consistent.
Assistant
Formatting is correct. Let me run the lint:
Assistant
Lint passes. Now let me run a broader set of tests to make sure I haven't broken anything in the error handling pipeline. Let me run the global-error compat integration test to be sure:
Assistant
All 22 global-error compat tests pass (both dev and production preview). The stderr lines are expected console.error logs from the head resolution failure path which is a different (existing) code path.
Let me run a broader integration test sweep on a few error-related tests to confirm nothing is broken.
Assistant
Assistant
The
DefaultGlobalErrorcomponent acceptserror: { digest?: string } | null | undefined, and safely accesseserror?.digest. Passingnullis fully supported and renders the client-error variant (no digest footer, "Reload to try again, or go back." with Back button).My fix is complete and correct. Let me do a final review of the complete modified function:
Assistant
Let me add a blank line between the
}and the comment for better formatting consistency:Assistant
Now let me re-run the formatter and the boundary render tests to confirm everything is still good:
Assistant
Everything passes. Let me do a final git status and diff review.
Assistant
The change is clean — only the source file
app-page-boundary-render.tsis modified. No test files or other artifacts were changed.Let me run one final broad test sweep across the most relevant test files to be thorough:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.