-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(router-core): use routeId for lifecycle hooks to fix onStay when loaderDeps change #6769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sheraff
merged 8 commits into
TanStack:main
from
sleitor:fix/router-lifecycle-use-routeid
Feb 27, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8f88f2
fix(router-core): use routeId for lifecycle hooks to fix onStay with …
sleitor 97ca146
ci: apply automated fixes
autofix-ci[bot] c8be9de
fix(router-core): separate cache identity (match.id) from lifecycle h…
sleitor eb67444
test(router-core): add caching regression + onBeforeNavigate coverage
sleitor 40e7176
test(router-core): consolidate /foo loaderDeps router setup into crea…
sleitor c78a89f
ci: apply automated fixes
autofix-ci[bot] b1e4206
Merge branch 'main' into fix/router-lifecycle-use-routeid
Sheraff e485707
fix: remove unused enteringMatches and stayingMatches variables
sleitor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change might mess up the caching behavior: a cache entry should be route id + params + deps (what we have currently). But I may agree that as far as lifecycle events are concerned, it may not exactly correlate with the cache changes.
I had codex whip up a quick test showing the expected cache behavior #6772. This test works on main and should fail w/ your PR.
Now we need to decide the semantics of those lifecycle events. Are they tied to the cache entries' lifecycles? Or are they more tied to the route itself (i.e. routeId)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great distinction to make. I think cache entries and lifecycle events serve different purposes and shouldn't necessarily share the same identity:
route + params + depsmakes sense here, because different params or deps mean different dataonEnter/onStay/onLeavedescribe whether a route is appearing, persisting, or disappearing in the matched treeFrom a user perspective, if I navigate from
/posts/123to/posts/456, I'd expectonStayfor the/posts/$idroute (the route is still there, just showing different data), notonLeave+onEnter. The cache correctly gets a new entry for456, but the route itself didn't leave.That said, I'm happy to defer to whatever semantics you and @schiller-manuel decide are correct here. If the conclusion is that lifecycle events should follow cache identity, I can revert and we can look for a different fix for #6765.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the semantics as you described them are correct. so we need to fix the caching regression that @Sheraff pointed out and then we can merge this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion — done in the latest commit. Merged
setupWithLoaderDepsandsetupWithLoaderDepsForCachinginto a singlecreateFooRouterhelper that accepts all options (onEnter/onLeave/onStay,loader,staleTime). All 9 tests still pass.