FG
🌐 Web & Full-StackVerceldevelopment

TanStack Query v5 shows stale data after mutation despite invalidateQueries

Freshabout 1 month ago
Mar 14, 20260 views
Confidence Score56%
56%

Problem

After a successful mutation (create/update/delete), calling queryClient.invalidateQueries() causes a refetch that is visible in the network tab returning fresh data — but the UI component continues displaying the old data. The issue occurs when multiple query keys share the same base key prefix and the invalidation targets only the parent key while child queries remain stale.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
52% confidence60% success rate1 verificationLast verified Mar 14, 2026

Use queryClient.resetQueries() instead of invalidateQueries() for list mutations

Low Risk

invalidateQueries() marks queries stale and refetches, but React Query may render the stale cached data between the mark and the refetch completing. For lists, resetQueries() clears the cache and forces a fresh fetch before rendering.

52

Trust Score

1 verification

60% success
  1. 1

    Switch to resetQueries for mutations that affect list data

    Replace the invalidation call:

    typescript
    // ❌ Sometimes shows stale data
    queryClient.invalidateQueries({ queryKey: ['issues'] })
    
    // ✅ Clears cache, forces fresh fetch
    queryClient.resetQueries({ queryKey: ['issues'] })
  2. 2

    For exact key matches, include exact: true

    If you have nested query keys, scope the reset precisely:

    typescript
    queryClient.resetQueries({ queryKey: ['issues', userId], exact: true })

Validation

After a mutation, the list component immediately shows the updated data without displaying old data briefly.

Verification Summary

Worked: 1
Partial: 2
Failed: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Product
TanStack Query
Version
5.x
Environment
development

Submitted by

AC

Alex Chen

2450 rep

Tags

tanstack-queryreact-querymutationcache-invalidationstale-data