router icon indicating copy to clipboard operation
router copied to clipboard

After 30 seconds, hovering on link with search param sets the search param

Open pontusdacke opened this issue 1 year ago • 1 comments

Describe the bug

After loading a page, and waiting 30 seconds, hovering on a link with a search param will set the search param. Its not set in the url unless you click, but the Route.useSearch() variable is set.

Your Example Website or App

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

Steps to Reproduce the Bug or Issue

  1. Go to stackblitz repro
  2. After page is loaded, wait 30 seconds.
  3. Hover "My link" with the mouse
  4. A text appears that renders from the search parameter caught from Route.useSearch().

Hovering before 30 does not cause issues.

Expected behavior

The search param should not be set by hovering.

Screenshots or Videos

No response

Platform

  • OS: Windows 11 Version 23H2 (Build 22631.3007)
  • Browser: Edge
  • Version: 121.0.2277.128
  • Chromium version: 121.0.6167.184

Additional context

No response

pontusdacke avatar Feb 20 '24 12:02 pontusdacke

The time is controlled by staleAge.

// Lower to 1 second
const router = createRouter({
  routeTree,
  defaultPreload: 'intent',
  defaultPreloadStaleTime: 1_000,
});

As a work-around, setting shouldReload: false in the Route mitigates the issue.

export const Route = createFileRoute('/')({
  component: Home,
  validateSearch: (search: Record<string, unknown>): MyParams => {
    return {
      categoryIds: search.categoryIds as string[] | undefined,
    };
  },
  shouldReload: false,
});

or setting the defaultPreload to false or undefined in the route setup.

// Set up a Router instance
const router = createRouter({
  routeTree,
  defaultPreload: false,
});

pontusdacke avatar Feb 21 '24 16:02 pontusdacke

should be fixed, please open a new issue if this is still relevant

schiller-manuel avatar Mar 27 '24 17:03 schiller-manuel

should be fixed, please open a new issue if this is still relevant

I'm curious to know which change you expected to fix this issue? 1.22.9 still has the issue, and 1.23.0 contains no relevant changes. I'll open a new issue tomorrow.

pontusdacke avatar Mar 27 '24 21:03 pontusdacke

I am experiencing this right now with v1.15.19. Have a few things I need to address before i can upgrade to the latest, but the shouldReload: false workaround appears to be working for me. Thank you for mentioning it.

allan-vera avatar May 07 '24 17:05 allan-vera