Link navigates using stale param despite the href using the updated param
I'm running into a bizarre situation where the links I render use the correct params but then navigating to them uses a stale param. For example:
1. Navigate to
/projects/$projectId where projectId: 1, which renders link that navigates to /projects/1/members with the same project id param used
2. Navigate to /projects/$projectId where projectId: 2, which renders link that navigates to /projects/1/members, despite the href being /projects/2/members
Am I doing something very wrong? It's tricky to figure out where to initially look but in terms of the code setting up routes and whatnot, things seem correct.
There's some router cache clearing and invalidation happening in between those, if that makes any difference.29 Replies
manual-pink•5w ago
is the link rendered correctly?
so does it have an href that points to 2?
wise-whiteOP•5w ago
yeah the link is rendered correctly
but clicking on the link navigates to the stale param (
1 in this example)manual-pink•5w ago
is this this issue? https://github.com/TanStack/router/issues/5655
GitHub
Link component active/inactive reactivity is not updated on param c...
Which project does this relate to? Router Describe the bug When I do a navigation trigering a param change, links active reactivity logic is not updated accordingly. If I pass explicitly the param ...
wise-whiteOP•5w ago
i don't think so?
manual-pink•5w ago
just a guess since i saw this
wise-whiteOP•5w ago
logging the route matches, can confirm that the params the link in question is using is based on the stale data
the issue seems to go away on a browser page reload
manual-pink•5w ago
can you reproduce this in a minimal example?
wise-whiteOP•5w ago
haven't been able to yet, annoyingly
lots of moving pieces so might take a while for me to narrow down
another interesting note: removing the loader for the link of interest seems to fix the issue
seems like updating the route that the link points to to use
beforeLoad instead of loader fixes the issue as well
tbh i still haven't fully grasped the practical differences between the twomanual-pink•5w ago
beforeLoad runs serially (from root down)
loaders run in parallel
loaders are cached, beforeLoad is not
wise-whiteOP•5w ago
ah maybe that last bit is a key detail?
manual-pink•5w ago
which renders link that navigates to /projects/1/membersis the "1" really in the url?
wise-whiteOP•5w ago
no just an example
it's more like a hex string that represents an ID
manual-pink•5w ago
yeah still, the url is incorrect? or just the rendered route
wise-whiteOP•5w ago
the URL is correct
what was being rendered is not
manual-pink•5w ago
ah, so this changes everything 😄
wise-whiteOP•5w ago
since it was using a stale param
manual-pink•5w ago
is this a path param or search param?
wise-whiteOP•5w ago
i could be misunderstanding your questions,
path param
manual-pink•5w ago
you wrote " that navigates to /projects/1/members"
wise-whiteOP•5w ago
oh shoot sorry
been a long day 😅 i meant to write that it navigates to
/projects/$projectId/members
maybe it would be more helpful for me to write out my specific case in more detail. Let's say I'm currently on this page:
It uses a beforeLoad . It has a link that navigates to:
This page has a loader. On this page, it has links that navigate to:
This page defines a loader as well.manual-pink•5w ago
oh using a _ suffix
wise-whiteOP•5w ago
yeah i meant to point that out in more detail, since I figure it might complicate things a bit
manual-pink•5w ago
there are some issues with this
which this flag resolves
manual-pink•5w ago
GitHub
router/packages/router-generator/src/config.ts at main · TanStack/...
🤖 A client-first, server-capable, fully type-safe router and full-stack framework for the web (React and more). - TanStack/router
manual-pink•5w ago
GitHub
fix(route-core, router-generator): resolve non-nested routes correc...
This PR reverts the work done in #5165, #5182 and #5169. These changes, although solving the original issue in #5164 introduced a slew of other problems related to trailing underscores, especially ...
manual-pink•5w ago
if that flag does not resolve your issue, we need to ask @Nico Lynzaad
wise-whiteOP•5w ago
that's for pointing to those! i'll give it a try
I also very much appreciate your patience - i know it's kind of a nightmare to have to get caught up with someone's specific usage without having a small example to work with
stormy-gold•5w ago
there is an issue with path params not updating in a non-nested route. it has to do with param not matching correctly in the non-nested route. unfortunately the fix for this does bring with it a change in the path ids. This is generally not a problem in new or smaller projects but unfrotunately we cannot make this change permanent now as it will affect larger projects, it has been scheduled to be the default with the next major release.
Setting the flag to true should resolve the issue.
wise-whiteOP•5w ago
wow i think that solved the issue
will need to do some more testing tomorrow but seems promising. thanks both!