Skip to content

About

Repro for TanStack/router#8128 — root renders with beforeLoad context stripped when navigating off a not-found page

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

TanStack Router: root loses its beforeLoad context when you navigate away from a 404 page

Navigate away from a not-found page and the root route re-renders with useRouteContext() empty, everything beforeLoad provided (locale, user, session) is briefly undefined. If anything reads that context during the navigation, it crashes. We see this ~95 times a day in production.

Run it

pnpm install
pnpm build
node serve.mjs
  1. Open http://localhost:3000/any-not-found-url, any broken URL, you get the 404 page.
  2. Click Back to dashboard.

The banner turns red: the root just rendered with context.locale === undefined (window.__LOCALE_RENDERS → ['en', 'undefined', 'en']). Deterministic, it happens every time.

Do the same navigation from a working page like /about, always fine. Coming from a 404 is what breaks it.

Why

  1. A not-found render marks the root match _notFound, so the next navigation rebuilds the root instead of reusing it (load-client.ts retention: ... || committed._notFound || ...).
  2. The rebuilt root has no context until its beforeLoad finishes (here: a session fetch, like the auth guide's getCurrentUserFn()). If the app has pending UI configured and the fetch outlasts pendingMs, the router publishes the root in this empty state.
  3. The root can't show pending UI (it owns <html>), so Match renders its real component, with the empty context.

In production we captured router state on every occurrence: all of them show this exact state (root pending, context reduced to the router base), across two triggers, leaving a 404, or navigating to a URL that turns out to be one.

Versions pinned: react-router 1.170.32, react-start 1.168.49 (router-core 1.171.27, which includes the context-preservation fix from #8130 - this still reproduces on it).

History: first reported from a hydration angle in #8129 (closed, the skew framing there pointed at URL handling, which this reproducer does not use).

About

Repro for TanStack/router#8128 — root renders with beforeLoad context stripped when navigating off a not-found page

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages