Solid Router: root `errorComponent` never catches re-thrown errors when `shellComponent` renders `<Outlet />` directly #6845
Which project does this relate to?#
Start
Describe the bug#
When using shellComponent on the root route, if the shell function renders <Outlet /> directly (instead of {props.children}), the root's errorComponent never catches errors re-thrown from a child route's errorComponent.
This happens because shellComponent receives the CatchBoundary (which wraps errorComponent) as part of its children prop. When the shell ignores children and renders <Outlet /> directly — which is the natural and common pattern — the CatchBoundary is never placed in the render tree. Re-thrown errors from child errorComponent have no parent boundary to propagate to.
The same route structure works correctly in @tanstack/react-router because React uses the component pattern where CatchBoundary wraps the component (which contains <Outlet />), keeping it in the render tree.
Root route (__root.tsx) — Solid:
export const Route = createRootRoute({
shellComponent: RootShell,
errorComponent: ({ error }) => (
<div data-testid="root-error">Root caught: {error.message}</div>
),
})
function RootShell() {
return (
<html>
<head>...</head>
<body>
<Outlet /> {/* ← renders Outlet directly, bypasses CatchBoundary in children */}
<Scripts />
</body>
</html>
)
}
Child route (test-error.tsx) — identical for both Solid and React:
export const Route = createFileRoute('/test-error')({
beforeLoad: () => { throw new Error('CHILD_THREW') },
component: () => <div>never renders</div>,
errorComponent: ({ error }) => {
if (error.message === 'HANDLE_THIS') return <div>handled</div>
throw error // ← re-throw to parent
},
})
Your Example Website or App#
https://github.com/ljho01/tanstack-solid-router-error-mre
Steps to Reproduce the Bug or Issue#
cd solid && pnpm install && pnpm dev- Open
http://localhost:3001/ - Click "Go to /test-error (client nav)"
- Page goes blank — root
errorComponentis never rendered
Compare with React:
cd react && pnpm install && pnpm dev- Open
http://localhost:3002/ - Click "Go to /test-error (client nav)"
- Root
errorComponentrenders correctly with "Root errorComponent caught: CHILD_THREW"
E2E tests (optional):
# Solid — 2 of 3 FAIL
cd solid && pnpm install && npx playwright install chromium && pnpm test:e2e
# React — 3 of 3 PASS
cd react && pnpm install && npx playwright install chromium && pnpm test:e2e
Expected behavior#
The root route's errorComponent should catch errors re-thrown from a child route's errorComponent, regardless of whether the shell renders <Outlet /> directly or uses {props.children}. This is consistent with how @tanstack/react-router behaves.
Screenshots or Videos#
No response
Platform#
- Router / Start Version: @tanstack/solid-router 1.166.2, @tanstack/solid-start 1.166.2
- OS: macOS 15.4
- Browser: Chrome 135
- Bundler: Vite 7.3.1
Additional context#
Root cause in source (@tanstack/solid-router/dist/esm/Match.js):
In the Outlet component, when routeId() === rootRouteId, the child <Match> is rendered inside a <Suspense> but not inside a CatchBoundary. The root's CatchBoundary only exists as a child of ShellComponent (passed via props.children), so if the shell doesn't render its children, the boundary is absent.
A possible fix is to wrap the child <Match> inside the Outlet with the root's CatchBoundary when shellComponent is in use:
// In Outlet, when routeId() === rootRouteId:
const rootRoute = () => router.routesById[rootRouteId];
const needsRootCatchBoundary = () =>
routeId() === rootRouteId && !!rootRoute().options.shellComponent;
// Wrap child match with CatchBoundary if shellComponent bypasses children
if (needsRootCatchBoundary() && rootErrorComponent()) {
return createComponent(CatchBoundary, {
getResetKey: () => resetKey(),
errorComponent: rootErrorComponent(),
onCatch: (error) => { /* ... */ },
children: childMatch(),
});
}
The repo includes a working patch in the linked reproduction.
Even simpler fix#
Realized the
shellComponentcheck is unnecessary. We can just unconditionally wrap the root Outlet's child<Match>withCatchBoundarywhenerrorComponentexists. A redundant boundary whenshellComponentrenders{props.children}is harmless — the inner one (fromMatch) catches first.The entire change is +2 declarations, +3 lines of JSX wrapping:
--- a/packages/solid-router/src/Match.tsx (Outlet function) +++ b/packages/solid-router/src/Match.tsx (Outlet function) @@ Outlet function, before return: const shouldShowNotFound = () => ... + const rootErrorComponent = () => router.routesById[rootRouteId]?.options.errorComponent ?? router.options.defaultErrorComponent; + const rootResetKey = useRouterState({ select: (s) => s.loadedAt }); @@ root route branch, inside <Suspense>: - <Match matchId={currentMatchId()}/> + {rootErrorComponent() + ? <CatchBoundary getResetKey={() => rootResetKey()} errorComponent={rootErrorComponent()} onCatch={(e) => { if (isNotFound(e)) throw e }}> + <Match matchId={currentMatchId()}/> + </CatchBoundary> + : <Match matchId={currentMatchId()}/>}No
shellComponentcheck, no helper functions, no extra reactive deps. Verified 3/3 E2E tests pass.Shell component is not supposed to render
Outlet.Correction & apology#
I confirmed this is not a Solid-only bug — React exhibits the exact same behavior when
shellComponentrenders<Outlet />directly instead of{props.children}.Pattern React Solid component+<Outlet />✅ pass N/A shellComponent+{props.children}✅ pass ✅ pass shellComponent+<Outlet />directly❌ fail ❌ fail As @schiller-manuel pointed out,
shellComponentis not supposed to render<Outlet />— it should render{props.children}, which includes the internalCatchBoundaryandmatchContext.Provider. My original comparison between React (componentpattern) and Solid (shellComponent+<Outlet />) was an apples-to-oranges comparison. I apologize for the noise.That said, this is a significant foot-gun: rendering
<Outlet />inshellComponentappears to work correctly (routes render, navigation works), but silently breakserrorComponentpropagation with no warning. Since the TanStack Start Solid template'sshellComponentrenders the full<html>document, it's a very natural (but wrong) pattern.Proposal: dev-mode console warning#
Instead of the CatchBoundary fix I submitted in #6847, I'd like to propose a runtime warning that fires when
<Outlet />is rendered insideshellComponentcontext. This would apply to bothreact-routerandsolid-router.Detection approach — add a context flag set inside
ShellComponent's children inMatch:// In Match component (root route rendering): <ShellComponent> <rootBoundaryContext.Provider value={true}> <matchContext.Provider value={matchId}> <CatchBoundary> ... </CatchBoundary> </matchContext.Provider> </rootBoundaryContext.Provider> </ShellComponent>// In Outlet: if (routeId === rootRouteId) { const insideRootBoundary = useContext(rootBoundaryContext) const hasShellComponent = route.options.shellComponent warning( !hasShellComponent || insideRootBoundary, 'Detected <Outlet /> rendered directly in shellComponent. ' + 'shellComponent should render {props.children} instead of <Outlet /> — ' + 'rendering <Outlet /> directly bypasses the error boundary and other internal wrappers, ' + 'which will break errorComponent propagation.' ) }This would only warn when the misuse pattern is detected (Outlet rendered for root route with shellComponent, but outside the normal boundary tree). Correct usage (
{props.children}) would not trigger the warning.I'll close the PR (#6847) if you'd prefer this direction.
the
matchContexthas been removed, what should I do ?birkskyum(GitHub profile, opens in a new tab) added labelspackage: solid-router
birkskyum(GitHub profile, opens in a new tab) added labelspackage: solid-start
Is this issue still relevant?
ljho01(GitHub profile, opens in a new tab) linked this to #6847
Sign in to join this conversation.
Working patch (source-level diff)#
Here's a minimal patch against
packages/solid-routerthat fixes this. The change is only in theOutletfunction insideMatch.jsx(~20 lines):What it does: When the current
Outletbelongs to the root route andshellComponentis configured, wrap the child<Match>with aCatchBoundaryusing the root'serrorComponent. This puts the boundary back in the render tree regardless of whethershellComponentrenders{props.children}or<Outlet />directly.Verified with E2E tests — Solid goes from 1/3 → 3/3 passing (matching React behavior).