feat(router-core): expose destination location to route lifecycle hooks#7817
feat(router-core): expose destination location to route lifecycle hooks#7817FrancoKaddour wants to merge 1 commit into
Conversation
onEnter, onStay, and onLeave now receive a second argument with the resolved destination ParsedLocation of the navigation that triggered them. Consumers previously had access to the route match but not the destination URL or search state. Closes TanStack#7778
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughRoute lifecycle hooks now receive a second context argument containing the resolved destination location. The callback types, runtime invocation, documentation, and tests cover ChangesDestination location lifecycle hooks
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant RouterCore
participant RouteLifecycleHook
participant DestinationLocation
RouterCore->>RouteLifecycleHook: invoke lifecycle hook with match and ctx
RouteLifecycleHook->>DestinationLocation: read ctx.location
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
LadyBluenotes
left a comment
There was a problem hiding this comment.
This is looking good overall. The shared router-core implementation is a nice fit, and the runtime coverage looks solid.
Could you also add direct type coverage for the new callback argument in:
packages/react-router/tests/route.test-d.tsxpackages/solid-router/tests/route.test-d.tsx
Each lifecycle callback could accept ctx and assert that ctx.location is ParsedLocation. It would also be useful to pin the deliberately unparameterized ctx.location.search type.
The existing type suites pass, but those callbacks currently only inspect match, so this would make sure the new public API stays covered.
|
View your CI Pipeline Execution ↗ for commit 6b82c27
☁️ Nx Cloud last updated this comment at |
Merging this PR will degrade performance by 16.6%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | mem client loader-data-retention (solid) |
157.7 KB | 581.8 KB | -72.89% |
| ❌ | Memory | mem client loader-data-retention (react) |
203.9 KB | 645.3 KB | -68.4% |
| ❌ | Memory | mem server error-paths redirect (vue) |
304.3 KB | 409.6 KB | -25.71% |
| ❌ | Memory | mem server error-paths redirect (solid) |
441 KB | 527.2 KB | -16.35% |
| ❌ | Memory | mem server error-paths unmatched (react) |
641.2 KB | 764.1 KB | -16.09% |
| ❌ | Memory | mem client loader-data-retention (vue) |
594.9 KB | 707.6 KB | -15.93% |
| ❌ | Simulation | client-preload interaction loop (react) |
57.3 ms | 60.7 ms | -5.51% |
| ❌ | Simulation | ssr control-flow unmatched 404 (react) |
59 ms | 62.1 ms | -4.97% |
| ❌ | Memory | mem client preload-churn (react) |
610 KB | 632.8 KB | -3.6% |
| ⚡ | Memory | mem server peak-large-page (react) |
2,080.9 KB | 947.8 KB | ×2.2 |
| ⚡ | Memory | mem server serialization-payload (react) |
5.3 MB | 3.4 MB | +53.24% |
| ⚡ | Simulation | ssr streaming deferred (react) |
73.1 ms | 70.6 ms | +3.59% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing FrancoKaddour:feat/lifecycle-hooks-destination-location (6b82c27) with main (11a6a0d)
Closes #7778
onEnter, onStay, and onLeave now receive a second argument exposing the resolved
destination location of the navigation that triggered them:
Implementation
is the resolved destination location of the current navigation.
typed { location: ParsedLocation } following the file's existing convention of not
supplying the search schema in route-option locations.
location being left — the match itself already carries the departed state.
Tests
and search state.
Docs
Summary by CodeRabbit
New Features
Documentation