fix(offline): include provided in RTKQ rehydration payload
RTK Query 2.12's invalidation slice reads `provided.tags` during cache
rehydration (`Object.entries(provided.tags ?? {})`). Our persisted
snapshot only carried `{ queries, mutations }`, so `provided` was
undefined and `.tags` threw on every startup with a cached snapshot —
crashing the app inside the rehydrate reducer / immer produce.
Snapshot now carries the real `provided` (so invalidation tags
rehydrate), and `load()` defaults it to `{ tags: {}, keys: {} }` so
snapshots persisted before this field existed recover without a manual
localStorage clear.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,23 @@ test('rehydrateApiCache replays a stored cache as a rehydrate action', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('rehydrate payload always carries `provided` (regression: RTKQ reads provided.tags)', () => {
|
||||
// A snapshot persisted before `provided` existed must not crash RTKQ's
|
||||
// invalidation slice, which does `Object.entries(provided.tags ?? {})`.
|
||||
instanceStorage.set(
|
||||
'rtkq',
|
||||
JSON.stringify({
|
||||
queries: { 'getLibrary(undefined)': { status: 'fulfilled', data: [] } },
|
||||
mutations: {},
|
||||
}),
|
||||
);
|
||||
const dispatched: Array<{ payload: { provided?: unknown } }> = [];
|
||||
rehydrateApiCache((a) =>
|
||||
dispatched.push(a as { payload: { provided?: unknown } }),
|
||||
);
|
||||
expect(dispatched[0].payload.provided).toEqual({ tags: {}, keys: {} });
|
||||
});
|
||||
|
||||
test('startApiPersistence saves only fulfilled queries after throttle', () => {
|
||||
rstest.useFakeTimers();
|
||||
let state = apiStateWith({});
|
||||
|
||||
Reference in New Issue
Block a user