Skip to content

test(router-core): add same-route cache regression coverage#6772

Open
Sheraff wants to merge 1 commit intomainfrom
test/router-core-same-route-cache-regression
Open

test(router-core): add same-route cache regression coverage#6772
Sheraff wants to merge 1 commit intomainfrom
test/router-core-same-route-cache-regression

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Feb 26, 2026

Summary

  • add a new same-route match caching test block in packages/router-core/tests/load.test.ts
  • cover two regression scenarios where match identity changes but route identity stays the same:
    • loaderDeps changes from search updates (/foo?page=1 -> /foo?page=2 -> /foo?page=1)
    • path param changes (/posts/1 -> /posts/2 -> /posts/1)
  • assert that previous match variants remain in cachedMatches and are reused within staleTime (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.ts

Summary by CodeRabbit

  • Tests
    • Added test coverage for caching behavior with identical routes using loader dependencies and path parameters to ensure proper cache reuse and validation within the configured staleTime window.

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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4027b6 and d8b4143.

📒 Files selected for processing (1)
  • packages/router-core/tests/load.test.ts

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
Router Core Tests
packages/router-core/tests/load.test.ts
Adds "same-route match caching" test suite with two test cases verifying cache reuse for identical loaderDeps and path parameter variants, including helper setup functions for route creation with caching configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

package: router-core

Suggested reviewers

  • schiller-manuel
  • brenelz

Poem

A speedy rabbit tests the cache's might, 🐰
Paths and loaderDeps stay fresh and bright,
Within staleTime's window, matches dance,
Cached tunnels reuse their second chance,
Testing routes with hoppy cheer! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding regression test coverage for same-route caching behavior in router-core.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/router-core-same-route-cache-regression

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 26, 2026

View your CI Pipeline Execution ↗ for commit d8b4143

Command Status Duration Result
nx run tanstack-router-e2e-bundle-size:build --... ✅ Succeeded 1m 26s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-26 17:32:21 UTC

@github-actions
Copy link

Bundle Size Benchmarks

  • Commit: 30bc35dc300b
  • Measured at: 2026-02-26T17:18:56.741Z
  • Baseline source: history:6b4213899882
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 86.57 KiB 0 B (0.00%) 272.38 KiB 75.30 KiB █▁▁▁▁▁▁▁▁▁▃
react-router.full 89.60 KiB 0 B (0.00%) 282.71 KiB 77.92 KiB █▁▁▁▁▁▁▁▁▁▃
solid-router.minimal 35.87 KiB 0 B (0.00%) 107.49 KiB 32.26 KiB █▁▁▁▁▁▃▃▃▃▄
solid-router.full 40.20 KiB 0 B (0.00%) 120.54 KiB 36.11 KiB █▁▁▂▂▂▃▃▃▃▄
vue-router.minimal 51.74 KiB 0 B (0.00%) 147.46 KiB 46.49 KiB █▁▁▂▂▂▄▄▄▄▅
vue-router.full 56.53 KiB 0 B (0.00%) 163.05 KiB 50.80 KiB █▁▁▁▁▁▂▂▂▂▃
react-start.minimal 99.10 KiB 0 B (0.00%) 311.51 KiB 85.70 KiB █▁▁▁▁▁▁▁▁▁▂
react-start.full 102.47 KiB 0 B (0.00%) 321.29 KiB 88.61 KiB █▁▁▁▁▁▁▁▁▁▃
solid-start.minimal 48.18 KiB 0 B (0.00%) 145.06 KiB 42.59 KiB █▁▁▂▂▂▃▃▃▃▄
solid-start.full 53.66 KiB 0 B (0.00%) 160.97 KiB 47.34 KiB █▁▁▁▁▁▃▃▃▃▄

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6772

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6772

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6772

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6772

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6772

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6772

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6772

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6772

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6772

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6772

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6772

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6772

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6772

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6772

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6772

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6772

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6772

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6772

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6772

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6772

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6772

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6772

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6772

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6772

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6772

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6772

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6772

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6772

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6772

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6772

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6772

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6772

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6772

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6772

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6772

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6772

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6772

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6772

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6772

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6772

commit: d8b4143

sleitor added a commit to sleitor/router that referenced this pull request Feb 27, 2026
…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.
sleitor added a commit to sleitor/router that referenced this pull request Feb 27, 2026
- 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant