Skip to content
Source
Sign inSign up
TanStack/router

beforeLoad doesn't get called #1752

Send to my agent
Closednucleartux(GitHub profile, opens in a new tab) opened this issue 6 comments

Describe 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

  1. Click "Go to the auth-only invoices page".
  2. Enter any login and access the authorized part of the site.
  3. Quickly click "Logout".
  4. Quickly click "Go to the auth-only invoices page" again.
  5. 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?

  1. I cannot reproduce this, maybe I am too slow :D can you please create a video?

  2. 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.

  3. is there any way this can be made easier reproducible? do those timeouts affect the behavior ?

  4. Actually, reproduction is much easier than it seemed.

    1. Hover over 'Go to the auth-only invoices page.'
    2. Move the cursor somewhere else.
    3. Click 'Go to the auth-only invoices page.'

    https://github.com/TanStack/router/assets/199706/c3fbb3ef-3be5-4f34-ac2c-f239a64a0d89

    If I set defaultPreload to false, everything works as expected.

  5. 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.

  6. SeanCassiere added labelsbug

Sign in to join this conversation.