Skip to content

cause uses cached match in beforeLoad and loader functions #3179

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

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