#4327·swr

Older Preload state overwrites a more recent mutated cached value

Author: TmanTmanCreated Sep 6, 2026Updated Sep 7, 2026

Bug report

Description / Observed Behavior

  1. A useSWR hook at someKey fetches and caches data. Some time after the fetch + cache, the hook unmounts (because of user navigation, etc).
  2. Subsequently, an element can trigger a preload to fetch data at someKey. The fetch completes (the network call promise resolves) but the data isn't consumed.
  3. After this, there is a local cache update through the global mutate function - mutate(someKey, (current) => ...)
  4. When the useSWR with someKey mounts again, the updated local cache value is overwritten by an old updated preload value

Expected Behavior

The more recent mutate should not be overwritten by a stale preload value.

Repro Steps / Code Example

https://stackblitz.com/edit/vitejs-vite-vqv17dcr?file=src%2FApp.tsx

Additional Context

SWR version: ^2.5.1

Related to some extent

  • #2529
  • #4193
  • #4194