Skip to content
Source
Sign inSign up
TanStack/router

Fix: Route with server function as loader that throws notFound crashes route on HMR #5763 #5890

MergedDeTuksa(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/5890/headmerged by birkskyum(GitHub profile, opens in a new tab)

Showing 3 changed files with 206 additions and 2 deletions.

x
0 of 3 viewed, 3 left
103 additions and 0 deletionspackages/react-router/tests/router.test.tsxModified
View file
@@ -1375,6 +1375,109 @@
expect(match.invalid).toBe(false)
+​
+ /**
+ * Regression test:
+ * - When a route loader throws `notFound()`, the match enters a `'notFound'` status.
+ * - After an HMR-style `router.invalidate({ filter })`, the router should reset that match
+ * back to `'pending'`, re-run its loader, and still render the route's `notFoundComponent`.
+ */
+ it('re-runs loaders that throw notFound() when invalidated via HMR filter', async () => {
+ const history = createMemoryHistory({
+ initialEntries: ['/hmr-not-found'],
+ })
+ const loader = vi.fn(() => {
+ throw notFound()
+ })
+​
+ const rootRoute = createRootRoute({
+ component: () => <Outlet />,
+ })
+​
+ const hmrRoute = createRoute({
+ getParentRoute: () => rootRoute,
+ path: '/hmr-not-found',