beforeLoad doesn't get called #1752
Send to my agentDescribe the bug#
I expect that every every time I enter the route beforeLoad will be called
Your Example Website or App#
https://stackblitz.com/edit/tanstack-router-94bxv9?file=src%2Froutes%2F_auth.tsx
Steps to Reproduce the Bug or Issue#
- Click "Go to the auth-only invoices page".
- Enter any login and access the authorized part of the site.
- Quickly click "Logout".
- Quickly click "Go to the auth-only invoices page" again.
- You are on the "Invoices" page without any authentication.
(You may need a few tries.)
Expected behavior#
On Step 4, loading happens again, and I'm redirected to the login page.
Screenshots or Videos#
No response
Platform#
"@tanstack/react-router": "^1.36.3",
"@tanstack/router-devtools": "^1.36.3",
"@tanstack/router-vite-plugin": "^1.38.0",
Additional context#
If it's expected behavior, how can I avoid it?
https://drive.google.com/file/d/1XcXgCSMdGj4KtGS0SAVlp86ZdDQSosIj/view?usp=sharing
(I was unable to upload the video to GitHub due to size restrictions. Sorry.)
You can fast forward the parts of the video where I wait for pages to load, by the way.
is there any way this can be made easier reproducible? do those timeouts affect the behavior ?
Actually, reproduction is much easier than it seemed.
- Hover over 'Go to the auth-only invoices page.'
- Move the cursor somewhere else.
- Click 'Go to the auth-only invoices page.'
https://github.com/TanStack/router/assets/199706/c3fbb3ef-3be5-4f34-ac2c-f239a64a0d89
If I set
defaultPreloadto false, everything works as expected.I've encountered this same behaviour. In my testing, It seems like the beforeLoad just doesn't run after the actual click if it has been preloaded from a hover and you haven't unhovered and then rehovered.
I think when you unhover and then hover again, because it's already preloaded, the hover doesn't trigger the beforeLoad again and therefore clicking works, but if the hover did trigger the preload and you click it without leaving the hover state, it never runs.
I'll likely be investigating this issue further next week so I'll update this post if I find any further information about what causes the issue.
this will be fixed by #1907
reproducer with pre-release package: https://stackblitz.com/edit/tanstack-router-v9onbn?file=src%2Froutes%2F_auth.tsx
SeanCassiere added labelsbug
Sign in to join this conversation.
I cannot reproduce this, maybe I am too slow :D can you please create a video?