Skip to content
Source
Sign inSign up
TanStack/query

Devtools incorrectly assume the staleTime from a disabled query #7055

Closednickbabcock(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

The devtools will assume the staleTime from a disabled query and show the data as stale, which differs from how the cache actually behaves (the staleTime of the data is Infinite).

const myEndpoint = () =>
  new Promise((res) => setTimeout(res, 5000)).then(() => 'hello world');

function Child() {
  useQuery({
    queryKey: ['example'],
    queryFn: myEndpoint,
    staleTime: Infinity,
  });

  return <div>Child</div>;
}

function App() {
  useQuery({
    queryKey: ['example'],
    queryFn: myEndpoint,
    enabled: false,
    staleTime: 0,
  });

  return <Child />;
}

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-ff9wjj?file=package.json,src%2Fmain.tsx,src%2FApp.tsx&terminal=dev

Steps to reproduce

  • Open devtools
  • Notice that the query is marked as stale
  • But that the query does not transition back to the fetching state after window is refocused (showing that the devtools)

Expected behavior

I expected the devtools to be consistent with the cache behavior.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows 11
  • Browser: Firefox 123

Tanstack Query adapter

react-query

TanStack Query version

5.25.0

TypeScript version

5.2.2

Additional context

No response

  1. Hey there! Would you be able to share some screenshots or videos? From what I've seen, the devtools seem to accurately reflect that the request is disabled initially, and the data for that request is empty. Then, after the request is triggered and disabled for a second time, it appears disabled, but this time the data shows up because it's already available in the cache

  2. Not sure I follow your thought. There are two useQuery with one perma-disabled, and only ever one request sent.

    The devtools show the query as stale:

    image

    If the query was stale then it should refetch on windows focus, right? But it doesn't. The inconsistency with cache behavior is the bug.

  3. isStale seems to return true for an observer with:

    enabled: false,
    staleTime: 0,

    however, for refetches, disabled observers aren't taken into account.

    I think the devtools do things correctly. The issue is that isStale is true for disabled observers. could be a missing check for options.enabled right here:

    https://github.com/TanStack/query/blob/5e648737524e18121213be243f791721c309a4b4/packages/query-core/src/queryObserver.ts#L572

  4. TkDodo assignedTkDodo

  5. TkDodo added labelsbug

  6. TkDodo added labelspackage: query-core

  7. TkDodo closed this

Sign in to join this conversation.