Skip to content
Source
Sign inSign up
TanStack/router

fix(solid-router): wrap root Outlet child with CatchBoundary #6847

Openljho01(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6847/headopened

When shellComponent renders <Outlet /> directly (the natural pattern) instead of {props.children}, the root's CatchBoundary from Match is never placed in the render tree. Errors re-thrown from a child route's errorComponent have no parent boundary to propagate to — the page goes blank.

Fix

Unconditionally wrap the root Outlet's child <Match> with a CatchBoundary using the root's errorComponent. The extra boundary is harmless when shellComponent does render {props.children} — the inner CatchBoundary (from Match) catches first.

1 file changed, +21 −3 — packages/solid-router/src/Match.tsx

Verification

Closes #6845

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling at the root level with improved error recovery and boundary management
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      Modifies the Outlet component in Match.tsx to conditionally wrap the root-level content in a CatchBoundary when a shellComponent is present. This ensures that the root's errorComponent properly catches errors re-thrown from child routes, regardless of whether the shell renders <Outlet /> directly.

      Changes

      Cohort / File(s)Summary
      Error Boundary Wrapping in Outlet
      packages/solid-router/src/Match.tsx
      Introduces rootErrorComponent and rootResetKey accessors, adds conditional CatchBoundary wrapping around child match content when a root error component exists, and ensures not-found errors propagate correctly via an onCatch handler that rethrows them. Replaces fallback rendering logic with explicit childMatch memoization.

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      Poem

      🐰 A boundary so wise, now guards the nested ways, When shells render outlets in their own display, Errors re-thrown find a parent at last, The root catches all—no escape through the past! One fix, one file, error handling's embrace. ✨

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title accurately describes the main change: wrapping the root Outlet child with CatchBoundary to fix error handling in solid-router.
      Linked Issues check✅ PassedThe code changes fully implement the fix for issue #6845: wrapping root Outlet child with CatchBoundary ensures root errorComponent catches re-thrown errors from child routes regardless of shellComponent implementation.
      Out of Scope Changes check✅ PassedAll changes in Match.tsx are directly scoped to fixing the root error boundary issue described in #6845; no unrelated modifications are present.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      Tip

      Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Share your feedback on Discord.


      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. Bundle Size Benchmarks

      • Commit: 4ea2a62787d0
      • Measured at: 2026-03-07T15:40:41.836Z
      • Baseline source: history:4ea2a62787d0
      • Dashboard: bundle-size history
      ScenarioCurrent (gzip)Delta vs baselineRawBrotliTrend
      react-router.minimal86.84 KiB0 B (0.00%)273.33 KiB75.44 KiB▁▁▁▁▁██████
      react-router.full89.88 KiB0 B (0.00%)283.67 KiB78.18 KiB▁▁▁▁▁██████
      solid-router.minimal36.24 KiB+68 B (+0.18%)108.66 KiB32.52 KiB▁▁▁▁▁▇▇▇▇▇▇█
      solid-router.full40.56 KiB+59 B (+0.14%)121.71 KiB36.39 KiB▁▁▁▁▁▇▇▇▇▇▇█
      vue-router.minimal52.03 KiB0 B (0.00%)148.42 KiB46.71 KiB▁▁▁▁▁██████
      vue-router.full56.85 KiB0 B (0.00%)164.01 KiB51.04 KiB▁▁▁▁▁██████
      react-start.minimal99.40 KiB0 B (0.00%)312.48 KiB85.98 KiB▁▁▁▁▁██████
      react-start.full102.78 KiB0 B (0.00%)322.29 KiB88.82 KiB▁▁▁▁▁██████
      solid-start.minimal48.53 KiB+43 B (+0.09%)146.25 KiB42.91 KiB▁▁▁▁▁▇▇▇▇▇▇█
      solid-start.full54.03 KiB+73 B (+0.13%)162.19 KiB47.62 KiB▁▁▁▁▁▇▇▇▇▇▇█

      Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

    4. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Inline comments:
      In `@packages/solid-router/src/Match.tsx`:
      - Around line 391-394: The root Match boundary changes must mirror the full root
      behavior: update the Match component logic that defines rootErrorComponent and
      rootResetKey so its onCatch handler forwards to the root/default onCatch (call
      or delegate to router.options.onCatch or the root route's onCatch) instead of
      swallowing errors, ensure isNotFound(error) results in rethrow only when a
      sibling root CatchNotFound is present otherwise forward to the root notFound
      handler (router.options.notFoundComponent or route-level notFoundComponent), and
      in the direct-Outlet shell path ensure ordinary errors still bubble to the root
      onCatch and descendant errorComponents that throw notFound(...) are captured by
      a sibling root CatchNotFound equivalent; locate and modify the onCatch/code
      paths and the error escalation flow near rootErrorComponent/rootResetKey and the
      Outlet-shell branch to delegate to the router's root/default handlers.

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 64dc9398-72ac-45b8-8c91-2580580f9124

      📥 Commits

      Reviewing files that changed from the base of the PR and between 4ea2a62787d0b7c562a4d13ecdca45c4ffb27092 and dc66bbd7154811a0cbb32167fff239238852f727.

      📒 Files selected for processing (1)
      • packages/solid-router/src/Match.tsx
      @@ -388,3 +388,7 @@
      388388 const shouldShowNotFound = () =>
      389389 childMatchStatus() !== 'redirected' && parentGlobalNotFound()
      390390
      391+ const rootErrorComponent = () =>
      392+ router.routesById[rootRouteId]?.options.errorComponent ??
      393+ router.options.defaultErrorComponent
      394+ const rootResetKey = useRouterState({ select: (s) => s.loadedAt })
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟠 Major

      Mirror the full root Match boundary behavior here.

      This restores the root errorComponent, but it still diverges from the normal root path at Lines 102-143: onCatch no longer forwards to the root/default onCatch, and isNotFound(error) is rethrown without a sibling root CatchNotFound. In the direct-<Outlet /> shell case, ordinary errors will skip root onCatch, and a descendant errorComponent that escalates with throw notFound(...) can still bypass the root notFoundComponent.

      Proposed parity fix
         const rootErrorComponent = () =>
           router.routesById[rootRouteId]?.options.errorComponent ??
           router.options.defaultErrorComponent
      +  const rootOnCatch = () =>
      +    router.routesById[rootRouteId]?.options.onCatch ??
      +    router.options.defaultOnCatch
      +  const rootNotFoundComponent = () =>
      +    router.routesById[rootRouteId]?.options.notFoundComponent ??
      +    router.options.notFoundRoute?.options.component
         const rootResetKey = useRouterState({ select: (s) => s.loadedAt })
      
         return (
      @@
                   <Solid.Suspense
                     fallback={
                       <Dynamic component={router.options.defaultPendingComponent} />
                     }
                   >
      -              {rootErrorComponent() ? (
      -                <CatchBoundary
      -                  getResetKey={() => rootResetKey()}
      -                  errorComponent={rootErrorComponent()!}
      -                  onCatch={(error) => {
      -                    if (isNotFound(error)) throw error
      -                  }}
      -                >
      -                  {childMatch()}
      -                </CatchBoundary>
      -              ) : (
      -                childMatch()
      -              )}
      +              <Dynamic
      +                component={rootErrorComponent() ? CatchBoundary : SafeFragment}
      +                getResetKey={() => rootResetKey()}
      +                errorComponent={rootErrorComponent() || ErrorComponent}
      +                onCatch={(error: Error) => {
      +                  if (isNotFound(error)) throw error
      +                  warning(false, `Error in route match: ${rootRouteId}`)
      +                  rootOnCatch()?.(error)
      +                }}
      +              >
      +                <Dynamic
      +                  component={
      +                    rootNotFoundComponent() ? CatchNotFound : SafeFragment
      +                  }
      +                  fallback={(error: any) => {
      +                    if (
      +                      !rootNotFoundComponent() ||
      +                      (error.routeId && error.routeId !== rootRouteId)
      +                    ) {
      +                      throw error
      +                    }
      +
      +                    return (
      +                      <Dynamic
      +                        component={rootNotFoundComponent()}
      +                        {...error}
      +                      />
      +                    )
      +                  }}
      +                >
      +                  {childMatch()}
      +                </Dynamic>
      +              </Dynamic>
                   </Solid.Suspense>

      Also applies to: 420-432

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In `@packages/solid-router/src/Match.tsx` around lines 391 - 394, The root Match
      boundary changes must mirror the full root behavior: update the Match component
      logic that defines rootErrorComponent and rootResetKey so its onCatch handler
      forwards to the root/default onCatch (call or delegate to router.options.onCatch
      or the root route's onCatch) instead of swallowing errors, ensure
      isNotFound(error) results in rethrow only when a sibling root CatchNotFound is
      present otherwise forward to the root notFound handler
      (router.options.notFoundComponent or route-level notFoundComponent), and in the
      direct-Outlet shell path ensure ordinary errors still bubble to the root onCatch
      and descendant errorComponents that throw notFound(...) are captured by a
      sibling root CatchNotFound equivalent; locate and modify the onCatch/code paths
      and the error escalation flow near rootErrorComponent/rootResetKey and the
      Outlet-shell branch to delegate to the router's root/default handlers.
    5. this needs tests. preferably unit tests, otherwise e2e tests

Sign in to join this conversation.