Skip to content

cause uses cached match in beforeLoad and loader functions #3179

Closed

Description

@ViewableGravy

Which project does this relate to?

Router

Describe the bug

Hovering a link while preloading is enabled for the router, will cause the loader to run with the cached cause value from the last the the route loader was cached.

If you refer to my reproduction, when loading to the / route and refer to the console logs, we can see that cause is always enter every time the "home" link is hovered. If we loaded the page on /about it is first preload and then correctly updates to enter when visiting /, but once on the page, and continuing to hover the home button, the cause remains as enter instead of stay.

Notice I have the version of the router set to 1.87.0. This looks to work find in 1.86.0 but all newer versions (tested all minor versions from 1.87 -> 1.97.1` with the same issue).

If I had to make an educated guess at what introduced this, I'd say commit 941ff2d probably had something to do with it, specifically line 2855 where we are no longer updating currently matched matches (which presumably causes cause to no longer get updated with "stay" because it's being skipped under that condition).

Not sure on a simple fix for this one since I am sure removing this condition will probably break existing features.

Thanks in advance

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-lddmwspa?file=src%2Froutes%2Findex.tsx

Steps to Reproduce the Bug or Issue

  1. Go to Home (/)
  2. Hover the Home button
  3. Observe the console printing cause: enter instead of cause: stay

Expected behavior

  1. Go to Home (/)
  2. Hover the Home button
  3. Observe the console printing cause: stay

Screenshots or Videos

Image

Platform

  • OS: Windows 11
  • Browser: Arc
  • Version: 1.87.0 -> 1.97.1

Additional context

Noticed this since our application has some redux actions in our loader that should only run when navigating to the page for the first time, however after upgrading, would cause them to run every time someone hovered a link on the page, which would also show a full page loader (and if the mouse was not moved from where the link would re-render after the loader, this would repeat indefinitely)

Activity

  1. ViewableGravy commented on Mar 2, 2025

    @ViewableGravy
    ContributorAuthor

    Just tested this one again with 1.112.0 and it still looks to be happening.

    I also noticed when re-testing on either version, that if you go from about to home, hovering has the cause "enter", but if you are already on the home route, click the button and then hover, it correctly updates. It seems to be only the case that cause doesn't update, when you are coming from another page, because the pre-fetch is preventing it from updating

  2. danivideda commented on Jun 9, 2026

    @danivideda

    Bumping this because the issue still persists in version 1.170.10, the current latest version.

    The loader still runs with cause: enter when it's just being hovered. Only after I press the link again does it correctly update the cause: stay and the hover doesn't trigger the loader function anymore.

  3. lpic10 commented on Jun 9, 2026

    @lpic10

    Also preload seems to always be false when hovering the links.
    I noticed this issue when trying to avoid running some auth checks on beforeLoad during preload
    I don't find a consistent way to know if the route is actually being preloaded.

  4. danivideda commented on Jun 9, 2026

    @danivideda

    Also preload seems to always be false when hovering the links.

    Perhaps the defaultPreload is set to false in your createRouter, or in the <Link> props itself? Because if that’s the case, I don’t think it’s related to this issue thread

  5. lpic10 commented on Jun 9, 2026

    @lpic10

    Also preload seems to always be false when hovering the links.

    Perhaps the defaultPreload is set to false in your createRouter, or in the <Link> props itself? Because if that’s the case, I don’t think it’s related to this issue thread

    I have it set to 'intent' but you are right, it is not related to this thread.

    After testing I see that it correctly set preload to true in the attached stackblitz when in the About page and hovering Home. Maybe the issue I have is because I set the beforeLoad in a layout page down the hierarchy, so maybe that cause other links in the same layout page to receive preload: false . I will open a separated issue if I can reproduce with a small example.

  6. danivideda commented on Jun 16, 2026

    @danivideda

    @schiller-manuel is this an expected behavior for the loader to run on hover <Link> with cause: enter and not cause: preload?

  7. danivideda commented on Aug 5, 2026

    @danivideda

    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions