fix(react-router): render the pending document root only when its beforeLoad context exists - #8129
Conversation
…oreLoad context exists The document-root pending exception keeps rendering the real component because pending UI would remove <html> and hydrated matches retain their prior data. An uncommitted hydrated root has no prior data: hydrate() only merges the dehydrated beforeLoad context (b) for committed matches, so an id-mismatched or stale root renders with every beforeLoad-provided context key missing (TanStack#8115's production symptom, still present with TanStack#8116). Track beforeLoad settlement on the client (__beforeLoadContext, mirroring load-server) and via the dehydrated b for committed hydration, and gate the document-root exception on it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe router now stores and restores ChangesHydration context handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized hydration fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains. Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Our root route gets its locale from
beforeLoadcontext. About 95 times a day the root renders with that context missing and the app crashes.We first blamed hydration, but production traces showed the real trigger: people navigating away from a 404 page. The 404 stops the router from reusing the root match, the rebuilt root has no context until
beforeLoadfinishes, and it gets rendered anyway.One-click repro: https://github.com/antur84/tanstack-router-8128-repro — open any broken URL, click the 404 page's link.
The fix tracks whether
beforeLoadhas actually contributed to the current context, and only then lets a pending document root render its real component. Two regression tests: the hydration case and the 404-navigation case.Fixes #8128.