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 analyze the repository structure first to understand the codebase.
Assistant
Now let's look at
app-page-boundary.tsto understand how the global error is wrapped:Assistant
Now let me look at how the global error module is rendered and where the self-throwing issue happens:
Assistant
Now let me search for
shouldRerenderAppPageWithGlobalErrorto see where this is invoked:Assistant
Now let me look at how
renderErrorBoundaryPage(which is the call ultimately being invoked when rendering the global error) works:Assistant
Now let me understand the test structure to find existing tests:
Assistant
Let me look at the actual rendering to understand how the error boundary renders the global error. The key issue is: "If the global error component itself fails, return the built-in valid HTML fallback". Let me investigate the rendering flow more carefully:
Assistant
Now let me look at how Next.js handles a self-throwing global error. Let me look at the existing default global error module to understand what we render:
Assistant
Now let me check how Next.js handles this. Let me look for tests on Next.js's behavior and what the issue expects:
Assistant
Now let me look at how the rendering works in detail, specifically how the RSC stream is constructed and where errors would happen:
Assistant
Now let me look at the
renderAppPageErrorBoundaryfunction and understand its flow better:Assistant
Now let me check the Next.js source on global-error to see what they do when global-error itself throws:
Assistant
Now let me look at the error boundary shim to understand the global error boundary:
Assistant
Now I have a good understanding. Let me look at the rsc-handler to understand how rendering happens and what happens when global-error throws:
Assistant
Now let me understand what happens with the
DefaultGlobalErrorwhen it throws. Let me also examine more carefully how the rendering happens:Assistant
Now I see the flow. The
renderAppPageErrorBoundaryfunction renders the global error (or page error) component. If the global error component itself fails (throws during rendering), this exception propagates. The key is to ensure a last-resort UI: a built-in valid HTML fallback.Let me look at the rscErrorTracker to understand how the rendering catches errors during RSC:
Assistant
Now let me understand where the rendering of the global error happens. Let's look at where the global-error gets rendered to see what happens if it throws:
Assistant
Now I have enough context. Let me search for how this might look in the Next.js source for reference:
Assistant
Now let me check tests/nextjs-compat/global-error.test.ts:
Assistant
Now let me check the existing tests for the boundary-render file:
Assistant
Now let me look at the existing test to understand what should change. Let me also look at app-page-boundary.test.ts:
Assistant
Now I have a clear understanding. Let me look at the most important flow. When
renderAppPageErrorBoundaryis called with a global error component and the component throws during rendering, what happens?Let me trace through:
renderAppPageErrorBoundaryis called- The
errorBoundary.componentis the global error component - It tries to render it - this happens inside
renderAppPageBoundaryElementResponse renderToReadableStreamis called with the element (which includes the global error component)- If the global error component throws, the error propagates
The current code doesn't catch errors during the rendering of the global error component itself. Let me check the rendering chain more carefully:
Assistant
Now let me check if there's a way to render a static HTML string (since the default global error is just static HTML). The fix should: catch errors when rendering the global error, and fall back to a built-in valid HTML.
Let me look at the test that currently expects the global error content:
Assistant
Now let me also understand the test file more deeply. Let me look at what is the expected behavior when the global-error component itself throws:
Assistant
Now I have enough context to make the fix. The issue is:
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.
The fix should be: when rendering the global error component, if the rendering throws an exception, we should fall back to the built-in default global error HTML.
Let me first run the existing tests to make sure they pass:
Assistant
Let me check if there's a way to run vitest with no coverage and faster:
Assistant
Good, now I have a working test setup. Let me also run the boundary test:
Assistant
Now let me write a reproducer script to demonstrate the issue before fixing it:
Assistant
Let me focus on the actual analysis. Let me look at the test setup to write a proper repro:
Assistant
I need to fix the test setup. Let me look at the existing test's renderElementToStream:
Assistant
Now let me update my test:
Assistant
Now I've reproduced the issue: when the global error component throws, the entire response fails. Let me think about the fix:
The fix needs to:
- Catch errors when rendering the global error component
- If the global error component fails, return a built-in valid HTML fallback with status 200
- Preserve response headers and cookies
- Preserve local error boundary semantics (which already work)
- Preserve framework navigation/control-flow signals (redirect, notFound, etc.)
- Don't expose the original boundary exception
Now let me look at the actual rendering pipeline to understand where the failure happens:
Assistant
Assistant
Now let me design the fix. The cleanest approach is:
- In
renderAppPageErrorBoundary, when the boundary is a global error, wrap the rendering in a try/catch - If it throws, fall back to using the
DefaultGlobalErrordirectly with a pre-rendered HTML string
Let me look at how the rendering pipeline is structured. The current pipeline renders an RSC element first, then SSR. The default global error is a simple HTML document, so we can render it directly to a string without RSC.
Let me check the structure of the existing code one more time:
- In
Assistant
Now let me design the fix. I'll modify
renderAppPageErrorBoundaryto:- When it's a global error boundary, wrap the rendering in a try/catch
- If the rendering throws, use the built-in default global error HTML
Let me look at the existing
renderAppPageErrorBoundaryfunction more carefully and plan the modification:Assistant
Now I understand the full picture. Let me also look at the
renderAppPageBoundaryElementResponsefunction to understand the rendering:Assistant
Now let me think about the solution. The cleanest approach is:
- In
renderAppPageErrorBoundary, when the resolved boundary is a global error, wrap the rendering in a try/catch - If the rendering throws, fall back to a built-in default global error HTML
The built-in default global error is a self-contained HTML document. We can pre-render it (using
renderToString) to a static HTML string and return that as the response body. This is safe because the default global error doesn't have any dynamic dependencies.Let me look at the React imports and see how I can render the default global error to a string:
- In
Assistant
Now let me think about the design carefully. The fix should:
- When the global error component itself fails, return a built-in valid HTML fallback
- The built-in fallback should be the
DefaultGlobalErrorfromdefault-global-error.tsx - Preserve response headers and cookies (status 200, content-type, vary, etc.)
- Don't expose the original exception
Let me design the fix:
In
renderAppPageErrorBoundary:- If
errorBoundary.isGlobalError, wrap the call torenderAppPageBoundaryElementResponsein a try/catch - If rendering throws, return a Response with the pre-rendered default global error HTML
Let me look at the import structure more carefully:
Assistant
Now let me think about the design. The fix needs to:
- When the global error component throws during rendering, return a built-in valid HTML fallback
- The built-in fallback should be the
DefaultGlobalErrorfromdefault-global-error.tsx - Preserve response headers and cookies
The simplest approach is to wrap the rendering in a try/catch and use the default global error HTML as the fallback. Let me design the fix:
Assistant
Now let me think about the cleanest implementation. The fix should be in
renderAppPageErrorBoundarybecause that's where the global error is handled. If the rendering throws, we should fall back to a built-in default.The key insight is that the
DefaultGlobalErroris a self-contained HTML document. We can pre-render it to a string usingrenderToStaticMarkupand return that as the response body.Let me now implement the fix:
Assistant
Now let me think about the cleanest implementation. The fix should:
- In
renderAppPageErrorBoundary, when the boundary is a global error, wrap the rendering in a try/catch - If the rendering throws, return a Response with the pre-rendered default global error HTML
Since we're using
react-dom/server.edgefor therenderToReadableStream, we can userenderToStaticMarkupfrom the same module to pre-render the default global error.Let me look at the existing code to understand how to add
renderToStaticMarkupimport:- In
Assistant
Now let me think about the implementation. The simplest approach is:
- In
renderAppPageErrorBoundary, whenerrorBoundary.isGlobalErroris true, wrap the rendering in a try/catch - If it throws, use
renderToStaticMarkupfromreact-dom/server.edgeto render theDefaultGlobalErrorto a string - Return a Response with the pre-rendered HTML
But wait - the
renderAppPageErrorBoundaryis inapp-page-boundary-render.ts, which is in the server directory. TheDefaultGlobalErroris inshims/default-global-error.tsx. Let me check if we can import it:- In
Assistant
Good, we can import it. Now let me also think about the RSC case. For RSC requests, the global error component is wrapped in an (the client-side error boundary). The RSC stream might fail if the global error component throws. But in the RSC case, the error is caught by the and the fallback is rendered.
Assistant
Now let me look at how the response is constructed for the global error to understand what headers/cookies to preserve:
Assistant
Now let me design the fix. The approach is:
- In
renderAppPageErrorBoundary, when the boundary is a global error, wrap the rendering in a try/catch - If it throws, create a Response with the pre-rendered default global error HTML
The key challenge is that we need to preserve the response headers and cookies. Let me look at what headers are set:
From
renderAppPageHtmlResponse:Content-Type: text/html; charset=utf-8Vary: ${VINEXT_RSC_VARY_HEADER}Link: <fontLinkHeader>(if fontLinkHeader)- Edge runtime header
- Middleware headers (which includes cookies)
For the fallback, we should preserve these headers. But since we're constructing a new Response, we need to capture the headers from the middleware context.
Let me now implement the fix. The approach is:
- In
renderAppPageErrorBoundary, when the boundary is a global error, wrap the rendering in a try/catch - If it throws, build a Response with the default global error HTML and the appropriate headers
Let me look at how the headers are constructed to understand what we need to preserve:
- In
Assistant
Now I understand the full picture. Let me implement the fix. The approach is:
- In
renderAppPageErrorBoundary, when the boundary is a global error, wrap the rendering in a try/catch - If it throws, create a Response with the pre-rendered default global error HTML and the appropriate headers
The key is to:
- Use
renderToStaticMarkupfromreact-dom/server.edgeto render theDefaultGlobalErrorto a string - Build a Response with status 200
- Preserve the headers from the middleware context (which includes cookies)
- Set the appropriate Content-Type and Vary headers
Let me now implement the fix. I'll modify
renderAppPageErrorBoundaryinapp-page-boundary-render.ts:- In
Assistant
Now let me implement the fix. I'll add a helper function that creates a fallback HTML response when the global error component throws:
Assistant
Now let me implement the fix. I'll modify the
renderAppPageErrorBoundaryfunction to wrap the rendering in a try/catch when the boundary is a global error:Assistant
Now let me implement the fix. I'll modify the
renderAppPageErrorBoundaryfunction to wrap the rendering in a try/catch when the boundary is a global error:Assistant
Let me use a different approach to edit the file directly:
Assistant
Now let me verify the changes:
Assistant
I need to import
VINEXT_RSC_VARY_HEADER:Assistant
Let me add the import:
Assistant
Now let me verify the changes:
Assistant
Now let me verify the function changes:
Assistant
Good. Now let me run the existing tests to make sure nothing is broken:
Assistant
Existing tests pass. Now let me update my repro test to verify the fix works:
Assistant
The fix works. The self-throwing global error now returns the built-in valid HTML fallback. Let me now run the broader tests to make sure nothing else is broken:
Assistant
Assistant
Good. Now let me also check if there are any other places where the global error component is rendered:
Assistant
This is the
wrapAppPageBoundaryElementfunction. It's called fromrenderAppPageErrorBoundaryandrenderAppPageHttpAccessFallback. For the global error case,includeGlobalErrorBoundaryisfalse, so the global error component is not wrapped in anErrorBoundary.Now let me also think about the
renderAppPageHttpAccessFallbackcase. This is used for not-found, forbidden, and unauthorized. For these cases, the global error component is used as a fallback boundary. If the global error component throws, the error would propagate.But wait - for
renderAppPageHttpAccessFallback, the global error component is used as a fallback for theErrorBoundarythat wraps the not-found/forbidden/unauthorized boundary. If the not-found boundary throws, theErrorBoundarycatches it and renders the global error component. If the global error component throws, the error would propagate.Let me check if this is handled:
Assistant
Assistant
Let me also run the error-related tests:
Assistant
Now let me also add a more comprehensive test to my repro to verify all the requirements:
- Returns a valid HTML response with status 200
- Preserves headers and cookies
- Doesn't expose the original exception
Assistant
Assistant
All tests pass. Let me also run the middleware tests:
Assistant
Let me also run the rsc-error-handler tests:
Assistant
Assistant
Assistant
There's an issue! The
react-dom/server.edgemodule doesn't exportrenderToStaticMarkup. Let me check what's available:Assistant
So
react-dom/server.edgedoes exportrenderToStaticMarkup. The issue is that the build is usingreact-dom/server.react-server.jsinstead. Let me check what's happening:Assistant
The issue is that the build is using
react-dom/server.react-server.jsinstead ofreact-dom/server.edge. Let me check what the build environment uses:Assistant
The issue is that the build is trying to resolve
react-dom/server.edgebut it's being aliased toreact-dom/server.react-server.jsin the RSC environment. Let me check the RSC client shim excludes:Assistant
Now let me understand the issue. The build is trying to resolve
react-dom/server.edgebut it's being mapped toreact-dom/server.react-server.jswhich doesn't exportrenderToStaticMarkup. Let me check the RSC environment configuration:Assistant
The issue is that
react-dom/server.edgeis being mapped toreact-dom/server.react-server.jsin the RSC environment. This is because in the RSC environment,react-dom/server.edgeis aliased toreact-dom/server.react-server.jswhich doesn't haverenderToStaticMarkup.Let me check how
app-ssr-entry.tshandles this:Assistant
So
app-ssr-entry.tsuses bothrenderToReadableStreamandrenderToStaticMarkupfromreact-dom/server.edge. This file is used in the SSR environment, not the RSC environment.The issue is that
app-page-boundary-render.tsis used in both the SSR and RSC environments. In the RSC environment,react-dom/server.edgeis aliased toreact-dom/server.react-server.jswhich doesn't haverenderToStaticMarkup.Let me check what
react-dom/server.react-server.jsexports:Assistant
So
react-dom/serverin thereact-servercondition maps to./server.react-server.js. This is what the RSC environment uses. Let me check whatserver.react-server.jsexports:Assistant
So
react-dom/server.react-server.jsjust throws an error. This meansreact-dom/server(without the.edgesuffix) is not available in the RSC environment.But
react-dom/server.edgeis a different module. Let me check:Assistant
So
react-dom/server.edgein thereact-servercondition also maps to./server.react-server.js. This means in the RSC environment,react-dom/server.edgeis also not available.So the issue is that
app-page-boundary-render.tsis used in both the SSR and RSC environments, and in the RSC environment,react-dom/server.edgeis not available.Let me check what
app-ssr-entry.tsdoes differently. It's used in the SSR environment, soreact-dom/server.edgeis available there.The fix is to use a different approach for the fallback. Instead of using
renderToStaticMarkup, I could:- Use a pre-rendered HTML string
- Use
ReactDOMServer.renderToString(which is available inreact-dom/server.edgebut not in the RSC environment) - Use a different module that exports
renderToString
Actually, let me check what
ReactDOMServeris available in the RSC environment. Looking at the test that's failing:Assistant
The issue is that
react-dom/server.edgeis not available in the RSC environment. Let me check what other files do:Assistant
So
app-page-boundary.tsdoesn't import fromreact-dom. Let me check whatapp-page-boundary-render.tscurrently imports:Assistant
I need a different approach. Let me use a pre-rendered HTML string instead of importing
renderToStaticMarkup. TheDefaultGlobalErrorcomponent is a static component that doesn't have any dynamic dependencies, so I can pre-render it to a string.Actually, let me look at the
default-global-error.tsxfile more carefully. It's a self-contained HTML document. I can just hardcode the HTML as a fallback.Wait, but the issue says "return the built-in valid HTML fallback". The "built-in" implies using the existing
DefaultGlobalErrorcomponent. Let me think about how to render it withoutrenderToStaticMarkup.One approach is to use
ReactDOMServer.renderToStringwhich is available inreact-dom/server.edge. But the issue is thatreact-dom/server.edgeis not available in the RSC environment.Let me check what
ReactDOMServeris available in the RSC environment. Looking at the test that's failing:The test is
tests/use-client-export-all-build.test.tswhich is a build test. Let me check what environment this test uses:Assistant
This test is building a Vite app with the vinext plugin. The build is failing because
react-dom/server.edgeis not available in the RSC environment.Let me check what
app-page-boundary-render.tsis used in. It's used in the SSR environment, not the RSC environment. Let me verify:Assistant
So
app-page-boundary-render.tsis used byapp-fallback-renderer.tswhich is used byapp-rsc-entry.ts. Theapp-rsc-entry.tsis the RSC entry, which is used in the RSC environment.So
app-page-boundary-render.tsis used in the RSC environment, wherereact-dom/server.edgeis not available.Let me check what
app-rsc-entry.tsdoes:Assistant
So
app-rsc-entry.tsdoesn't import fromreact-dom. It usesrenderToReadableStreamwhich is passed in as a parameter. Let me check:Assistant
So
app-rsc-entry.tsusesrenderToReadableStreamfrom@vitejs/plugin-rsc/rsc, not fromreact-dom/server.edge. This is why it works in the RSC environment.Now I need to understand why
app-page-boundary-render.tsis being used in the RSC environment. Let me check the build configuration:Assistant
I see. The RSC environment has
noExternal: truewhich forces allnode_modulesthrough Vite's transform pipeline. This meansreact-dom/server.edgeis being transformed in the RSC environment, and thereact-servercondition is applied, which maps it toreact-dom/server.react-server.jswhich doesn't haverenderToStaticMarkup.So the issue is that
app-page-boundary-render.tsis used in the RSC environment, andreact-dom/server.edgeis not available there.Let me think about how to fix this. I have a few options:
-
Use a pre-rendered HTML string: I can hardcode the HTML output of the
DefaultGlobalErrorcomponent as a string. This avoids the need to importreact-dom/server.edge.
-
Assistant
Assistant
Good, I have the pre-rendered HTML. Let me capture the full HTML:
Assistant
The output is truncated. Let me save the full HTML to a file:
Assistant
Now let me think about a better approach. Instead of hardcoding the HTML, let me take a different approach:
- Move the fallback function to a separate file that only imports
react-dom/server.edge - Use a dynamic import or lazy import to avoid loading the file in the RSC environment
Actually, let me try a simpler approach. Let me check if I can use
react-dom/server.nodeinstead:- Move the fallback function to a separate file that only imports
Assistant
Same issue -
react-dom/server.nodealso maps toreact-dom/server.react-server.jsin thereact-servercondition.Let me check if there's a way to import
react-dom/server.edgewithout thereact-servercondition. Looking at the package.json:"./server.edge": { "react-server": "./server.react-server.js", "default": "./server.edge.js" }In the
defaultcondition, it maps to./server.edge.js. So if I can avoid thereact-servercondition, I can use .Assistant
So
app-page-boundary-render.tsusesrenderToReadableStream(passed as a parameter) for rendering, and now usesrenderToStaticMarkupfor the fallback. TherenderToReadableStreamis passed from the caller, which uses the appropriate renderer for the environment.For the RSC environment, the
renderToReadableStreamis from@vitejs/plugin-rsc/rsc, which renders RSC streams. For the SSR environment, it's fromreact-dom/server.edge, which renders HTML streams.So the fallback function needs to use a renderer that's available in the current environment. But the fallback function is only called when the global error component throws, which is a rare case.
Assistant
Assistant
The output is still truncated. Let me use a different approach - I'll read the file directly:
Assistant
Good, now I have the full HTML. Let me think about a cleaner approach.
Actually, let me reconsider. Instead of hardcoding the HTML, let me move the fallback function to a separate file. This separate file will import
react-dom/server.edge, and the main file will use a dynamic import or a runtime check to load it.But the issue is that the import is resolved at build time. So even if I use a dynamic import, Vite would still try to resolve
react-dom/server.edgeat build time.Let me try a different approach. I'll use
import.meta.envor a runtime check to determine ifreact-dom/server.edgeis available. If it is, I'll use it. If not, I'll use a pre-rendered HTML string.Actually, let me try the simplest approach: use a pre-rendered HTML string. I'll hardcode the HTML as a constant. This avoids the need to import
react-dom/server.edgein the RSC environment.Let me read the full HTML:
Assistant
The output is still truncated by the terminal. Let me use a different approach - write the HTML directly to a file in the source tree:
Assistant
Good. Now let me update the
app-page-boundary-render.tsto use this pre-rendered HTML instead ofrenderToStaticMarkup:Assistant
Now let me run the tests to see if the build issue is fixed:
Assistant
The build test passes now. Let me run the broader tests:
Assistant
All 5831 tests pass. Let me also verify my fix still works with a quick test:
Assistant
All 5 verification tests pass. Let me clean up:
Assistant
Now let me also think about whether the fix handles the RSC case correctly. For RSC, the global error component is serialized as a reference. If the global error component throws during server-side rendering (e.g., if it's a server component), the error would propagate. My fix would catch this error and return an HTML response.
But for RSC, the client expects an RSC stream. Returning an HTML response is a degradation. Let me check if this is acceptable.
Looking at the issue: "If the global error component itself fails, return the built-in valid HTML fallback with the expected successful fallback status". The issue says "valid HTML fallback". So returning an HTML response is acceptable, even for RSC.
Let me also think about the case where the global error component is a client component. For client components, the rendering happens on the client. During server-side rendering, the client component is serialized as a reference. So the global error component wouldn't throw during server-side rendering.
But for server components, the rendering happens on the server. If the server component throws, the error would propagate. My fix would catch this error and return an HTML response.
Assistant
Let me check
app-page-route-wiring.tsxto see if the global error is rendered there:Assistant
This is where the global error is used as a fallback for the
ErrorBoundary. TheErrorBoundaryis a client component, so during server-side rendering, it's serialized as a reference. The actual rendering happens on the client.So this is not a case where the global error component throws during server-side rendering. My fix doesn't affect this case.
Let me now run the integration tests to make sure nothing is broken:
Assistant
All 22 integration tests pass. Let me also verify the fix is complete by looking at the final code:
Assistant
Now let me also think about edge cases:
-
The
tryblock in the fallback function: Since we're now using a pre-rendered HTML string (a constant), thetryblock won't throw. But I'll keep it for robustness. -
The
middlewareContext.headersis null: My fix handles this withoptions.middlewareContext.headers ?? null. -
The
routePatternis undefined: My fix usesoptions.route?.pattern ?? pathnamewhich is always defined. -
The
isEdgeRuntimeis undefined: My fix handles this withoptions.isEdgeRuntimewhich is optional.
Let me also check if there are any other tests I should run:
-
Assistant
The integration tests take too long. Let me run just the error-related ones:
Assistant
All tests pass. Let me also run the fallback-renderer tests:
Assistant
Let me also check if the fix needs to handle the RSC case differently. For RSC requests, the
renderToReadableStreamis from@vitejs/plugin-rsc/rsc, which renders RSC streams. If the global error component throws during RSC rendering, my fix would catch the error and return an HTML response. But the client expects an RSC stream.Let me check if this is a problem by looking at how the response is used in the RSC pipeline:
Assistant
The
renderErrorBoundaryPageis called fromapp-page-dispatch.tsand ultimately callsrenderAppPageErrorBoundaryinapp-page-boundary-render.ts. The response is returned to the caller.For the RSC pipeline, the response is returned to the client. If the response is HTML instead of RSC, the client would need to handle this.
Let me check if the RSC pipeline handles this case:
Assistant
Let me check if the RSC pipeline handles the case where the response is HTML instead of RSC:
Assistant
The RSC pipeline doesn't check the Content-Type. It just returns the response to the client. If the response is HTML, the client would receive an HTML response instead of an RSC stream.
For the client, this is a degradation. The client would need to handle the HTML response. But the issue says "return the built-in valid HTML fallback", so this is acceptable.
Let me now also think about whether I need to handle the case where the
renderAppPageErrorBoundaryfunction is called withisRscRequest: trueand the global error component throws. In this case, my fix would return an HTML response. But the client expects an RSC stream.Actually, let me re-read the issue one more time:
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.
The issue says "valid HTML fallback". So the fallback is HTML. For RSC, this is a degradation, but the issue doesn't distinguish.
OK, I think my fix is correct. Let me now do a final review of the code:
Assistant
Let me also add a changeset for this fix:
Assistant
I don't need to add a changeset since the existing changesets are auto-generated from commits.
Let me now do a final review of all the changes:
Assistant
The changes look good. Let me also verify the new file:
Assistant
Now let me also run the lint check to make sure the code passes:
Assistant
Let me also run the format check:
Assistant
Both files pass format checks. Let me run the tests one more time to make sure everything still works:
Assistant
All 41 tests pass. Let me also run the full unit test suite one more time to make sure nothing else is broken:
Assistant
All 5831 tests pass. Let me do a final review of the changes:
Assistant
The changes are:
-
Modified
packages/vinext/src/server/app-page-boundary-render.ts:- Added import for
DEFAULT_GLOBAL_ERROR_LAST_RESORT_HTML - Added import for
VINEXT_RSC_VARY_HEADER - Added imports for
applyEdgeRuntimeHeaderandmergeMiddlewareResponseHeaders - Added try/catch around
renderAppPageBoundaryElementResponsewhen the boundary is a global error - Added
renderAppPageGlobalErrorLastResortResponsefunction for the last-resort fallback
- Added import for
-
New file
packages/vinext/src/server/default-global-error-last-resort.ts:- Contains the pre-rendered HTML of the
DefaultGlobalErrorcomponent
- Contains the pre-rendered HTML of the
Let me verify the fix works correctly by running a quick test:
-
Assistant
Let me clean up:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.