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.
pnpm install
pnpm build
node serve.mjs- Open http://localhost:3000/any-not-found-url, any broken URL, you get the 404 page.
- 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.
- A not-found render marks the root match
_notFound, so the next navigation rebuilds the root instead of reusing it (load-client.tsretention:... || committed._notFound || ...). - The rebuilt root has no context until its
beforeLoadfinishes (here: a session fetch, like the auth guide'sgetCurrentUserFn()). If the app has pending UI configured and the fetch outlastspendingMs, the router publishes the root in this empty state. - The root can't show pending UI (it owns
<html>), soMatchrenders 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).