1228118027
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>
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { createAction } from '@reduxjs/toolkit';
|
|
|
|
/*
|
|
* Tier 2 offline support contract. RTK Query can seed its cache from a
|
|
* persisted snapshot via `extractRehydrationInfo` (see `api/index.ts`). We use
|
|
* a single action whose payload is the previously-saved api slice state; the
|
|
* api reducer pulls `queries`/`mutations` out of it on startup so last-seen
|
|
* library data renders read-only while the backend is unreachable.
|
|
*
|
|
* The type string lives here (not in the store) so `api/index.ts` can match it
|
|
* without importing from the store layer (which would create a cycle).
|
|
*/
|
|
export const REHYDRATE_API = 'api/rehydrate';
|
|
|
|
export interface RehydrateApiPayload {
|
|
queries: Record<string, unknown>;
|
|
mutations: Record<string, unknown>;
|
|
// RTKQ's invalidation slice reads `provided.tags`/`provided.keys` during
|
|
// rehydration (it does `Object.entries(provided.tags ?? {})`), so `provided`
|
|
// must be an object — a bare `{ queries, mutations }` makes it crash on
|
|
// `provided.tags` of undefined. Always present; empty objects are valid.
|
|
provided: { tags: Record<string, unknown>; keys: Record<string, unknown> };
|
|
}
|
|
|
|
export const rehydrateApi = createAction<RehydrateApiPayload>(REHYDRATE_API);
|