test(router-core): add same-route cache regression coverage#6772
test(router-core): add same-route cache regression coverage#6772
Conversation
Add focused loaderDeps and path-param tests that verify prior match variants remain cached and reusable within staleTime. This guards against lifecycle classification changes accidentally dropping cache entries keyed by match id.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA test suite is added to verify route-match caching behavior for identical routes with loaderDeps and path parameters, ensuring matches remain cached and reused within the configured staleTime window. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit d8b4143
☁️ Nx Cloud last updated this comment at |
Bundle Size Benchmarks
Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better. |
…ook identity (routeId) Cache entries use match.id (routeId + params + loaderDeps) so navigating between different params/deps correctly caches the previous match. Lifecycle hooks (onEnter/ onStay/onLeave) use routeId to track route *presence* in the matched tree — so navigating /posts/123 → /posts/456 fires onStay for /posts/$id, not onLeave+onEnter. Addresses caching regression spotted by @Sheraff in PR TanStack#6772 test.
- Add same-route match caching tests (from PR TanStack#6772 by Sheraff) to verify that switching lifecycle hooks to routeId does NOT break cache identity (which still correctly uses match.id = routeId + params + loaderDeps). Tests cover both loaderDeps variants and path param variants. - Add onBeforeNavigate subscription event tests to address SeanCassiere's request to verify router-level events still fire correctly after this change. These events are used by integrations like Sentry's TanStack Router instrumentation for page-transition tracking. All 1017 tests pass (29 test files, 0 type errors).
Summary
same-route match cachingtest block inpackages/router-core/tests/load.test.tsloaderDepschanges from search updates (/foo?page=1 -> /foo?page=2 -> /foo?page=1)/posts/1 -> /posts/2 -> /posts/1)cachedMatchesand are reused withinstaleTime(no extra loader call)Why
These tests guard against lifecycle-only identity changes accidentally affecting cache behavior keyed by match
id.Testing
CI=1 NX_DAEMON=false pnpm nx run @tanstack/router-core:test:unit --outputStyle=stream --skipRemoteCache -- tests/load.test.tsSummary by CodeRabbit