Fix: Route with server function as loader that throws notFound crashes route on HMR #5763#5890
Conversation
WalkthroughAdds a public RouterCore.invalidate(...) method and updates commit/invalidate logic so matches with status 'notFound' are treated like 'error' during invalidation and commit: errors are cleared and matching exits are reset to 'pending' (optionally via forcePending) so loaders re-run. Adds tests in React and Solid verifying loaders that throw or return notFound() re-run and notFoundComponent remains rendered. Changes
Sequence Diagram(s)sequenceDiagram
actor Dev
participant HMR as HMR System
participant Router as RouterCore
participant Loader as Route Loader
participant UI as Renderer
Dev->>HMR: Save file (HMR)
HMR->>Router: invalidate(filter?)
activate Router
Router->>Router: find matches matching filter
alt match status is 'error' or 'notFound' or opts.forcePending
Router->>Router: clear error, set status -> 'pending'
end
Router->>Loader: invoke loader for pending match
activate Loader
Loader-->>Router: returns data OR throws/returns notFound()
deactivate Loader
Router->>UI: render route data or notFoundComponent
deactivate Router
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-10-08T08:11:47.088ZApplied to files:
📚 Learning: 2025-10-01T18:30:26.591ZApplied to files:
🔇 Additional comments (2)
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 |
|
View your CI Pipeline Execution ↗ for commit 32a3f09
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/react-router/tests/router.test.tsx(1 hunks)packages/router-core/src/router.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/react-router/tests/router.test.tsx
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel
Repo: TanStack/router PR: 5330
File: packages/router-core/src/router.ts:2231-2245
Timestamp: 2025-10-01T18:30:26.591Z
Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.
Applied to files:
packages/router-core/src/router.ts
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
Applied to files:
packages/router-core/src/router.ts
|
@DeTuksa , can you add a similar test in the solid-router? |
|
Sure @birkskyum😀 I added these cases: |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@birkskyum I think the checks that failed are related to the cloudfare downtime yesterday😅 |
…tFound crashes route on HMR TanStack#5763 (TanStack#5890)
Resolves: #5763
Summary by CodeRabbit
New Features
Bug Fixes
Tests