Correctly load matched routes when navigated before preload is finished#1876
Correctly load matched routes when navigated before preload is finished#1876freshgiammi wants to merge 2 commits intoTanStack:mainfrom freshgiammi:preload_issues
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit bb19c1b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
|
There's still an issue here when with context when it gets merged with beforeLoad. Supposing This possibly happens because execution flow is skipped when a route already in |
|
are you able to reproduce this in a test somehow? this would be awesom. |
| options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>, | ||
| ): React.AnchorHTMLAttributes<HTMLAnchorElement> { | ||
| const router = useRouter() | ||
| const isClicking = React.useRef(false) |
There was a problem hiding this comment.
why do we need to track if a link was clicked?
what happens if we have two link instances pointing to the same target, this then won't work, right?
i think the solution must be independent from click tracking etc, and also must work when programatically preloading / navigating without clicking on a link
There was a problem hiding this comment.
this most likely needs to be fixed inside of router.ts
There was a problem hiding this comment.
This is a different issue than the references (so we could have it in a separate PR), but essentially onFocus is also invoked when a button is clicked, which causes the route to get preloaded twice (onMouseEnter + onFocus).
When focusing a link via keyboard navigation, we obviously skip onMouseEnter so it gets correctly preloaded once.
Given that there's no way to distinguish between mouse and keyboard origin for focus events, we can "trap" it by skipping the preload call when a focus event is detected between onMouseDown and onMouseUp: this makes preload only happen once and ensures that the behaviour is the same for both mouse and keyboard navigation.
There was a problem hiding this comment.
ok please put this in a separate PR then
The issue I'm still facing in #1876 (comment) should be easily reproducible. A test case for this preload issue when lazy components haven't finished fetching yet might be more complicated, but I haven't worked on either yet. Still, it could be something close to what I've done in the reproduction template |
|
Split #1876 (comment) into a separate issue: #1886 |
|
closing in favor of #1907 |
Ref: #1534
Ref: #1638