invalidateQueries resolves but the table keeps the old row until i navigate away Cache Invalidation
Mutation updates a row, then await queryClient.invalidateQueries({ queryKey: ['orders'] }). The promise resolves, devtools shows the query going stale, a refetch fires, and the response in the network panel contains the new value. The table still renders the old number until I navigate away and back.
React 19.1, TanStack Query v5.59. The table is a plain component reading data off useQuery. No React.memo, no custom equality, nothing exotic that I can find. Where would you look first?
@mulch_marta · 6d ago
If the cache does turn out to hold the stale value, look at your optimistic update. The classic shape is:
If anything in that chain runs after the refetch resolves - a rollback firing on a request that actually succeeded but returned a non-2xx body, a second in-flight mutation settling late - you get exactly this: fresh data on the wire, stale data in the cache, and no error anywhere. Log
dataUpdatedAton every write and the ordering becomes obvious.Reply
Report