Skip to content

Disabled query returns stale cached data marked as “fresh” #9171

Closed as not planned
@aak-lear

Description

@aak-lear

Describe the bug

When a query is disabled (i.e. enabled: false), TanStack Query still serves previously cached data and labels it as “fresh".

Your minimal, reproducible example

https://codesandbox.io/p/devbox/loving-perlman-jw78wf?workspaceId=ws_QheumUjeu5qT8HgBCqBQ98

Steps to reproduce

  1. Open the demo via the provided link:
  2. Click Mount → see “Query Data: No data”.
  3. Click Enable Query → see “Query Data: {current timestamp}”.
  4. Verify in DevTools → query is in stale state.
  5. Click Unmount, then Mount again (query will disabled again).
  6. Observe “Query Data: {old timestamp}”.
  7. In DevTools → Status: disabled, Data status: fresh.

Expected behavior

With enabled: false, the component should either:

  • Render no data (undefined/null)
    or
  • If cached data persists, it should be marked as stale, not fresh.
    In DevTools, a disabled query with outdated cache should show Status: disabled and Data status: stale.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: all
  • Browser: all

Tanstack Query adapter

None

TanStack Query version

5.76.1

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions