fix(api): refetch from server when online (stale-while-revalidate)
The Tier-2 rehydrated cache seeded fulfilled entries at startup, so RTKQ served stale data and never hit the network (manual metadata edits, etc. only appeared after clearing the cache). Enable refetchOnMountOrArgChange + refetchOnReconnect + refetchOnFocus and wire setupListeners, so the cached snapshot still shows instantly but the server silently revalidates it whenever reachable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import { setupListeners } from '@reduxjs/toolkit/query';
|
||||
import { api } from '../api';
|
||||
import authReducer from './slices/auth';
|
||||
import connectionReducer from './slices/connection';
|
||||
@@ -27,6 +28,10 @@ export const store = configureStore({
|
||||
getDefaultMiddleware().concat(api.middleware),
|
||||
});
|
||||
|
||||
// Enable refetchOnReconnect / refetchOnFocus by dispatching the browser's
|
||||
// online + focus events into RTKQ (no-op without the api flags set in api/index).
|
||||
setupListeners(store.dispatch);
|
||||
|
||||
// Flush queue/player changes back to localStorage (throttled).
|
||||
startPersistence(store);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user