You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(web): move persisted events to query state (#1922)
* refactor: use tanstack-query
* test(web): stabilize event query migration tests
* refactor(web): simplify event query configuration
* docs: design query-owned event server state
* feat(web): add event query cache utilities
* refactor(web): move persisted events to query state
* test(web): cover event mutation lifecycle
* refactor(web): simplify event query state
* refactor(web): simplify event mutations and test harness
- collapse the seven near-identical useMutation blocks behind a
buildMutation helper so the snapshot/optimistic/rollback/invalidate
lifecycle is defined once
- drop the unused eventMutationKeys.event key builder
- extract toNormalizedEventQueryData and reuse it across the three test
harnesses that hand-built the { ids, entities } cache shape
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1. a view hook mounts a `useXEventsQuery` hook (day/week/someday)
198
196
2. TanStack Query fetches via the pure query function against the repository
199
197
for the reactive source (`event.repository.source.store.ts`)
200
-
3.a per-hook effect syncs the normalized result into Redux (entities +
201
-
id-list slice), so selectors/grid render unchanged
198
+
3.the normalized result remains in the source- and range-aware query entry;
199
+
pure view models derive render data directly from it
202
200
4. changing the view range re-keys the query (fetch on new ranges, instant
203
201
render from cache on revisits within `staleTime`)
204
202
205
203
Typical event **mutation** flow:
206
204
207
-
1. a hook or component dispatches a Redux mutation action
208
-
2. Redux Toolkit listener middleware invokes an async event operation
209
-
3. the selected repository writes locally or remotely
210
-
4. the operation updates the event entity store and, on success, calls
211
-
`queryClient.invalidateQueries` so reads refetch instead of re-syncing
212
-
pre-mutation cache into Redux
213
-
5. Redux slices update async status
214
-
6. React re-renders from selectors
215
-
7. SSE events invalidate the relevant query scope (day/week/someday) to
205
+
1. a hook or interaction calls the narrow `EventMutations` interface
206
+
2. the mutation captures the active repository source, cancels Event reads,
207
+
and snapshots affected query entries
208
+
3. immutable cache utilities apply the optimistic update to matching ranges
209
+
4. failures restore every snapshot; settlement invalidates `eventQueryKeys.all`
210
+
5. pending guards derive Event IDs from TanStack Query mutation state
211
+
6. SSE events invalidate the relevant query scope (day/week/someday) to
216
212
refetch later; auth transitions refresh the source store and drop stale
217
213
cache entries
218
214
@@ -222,8 +218,8 @@ or treat them as stable.
222
218
223
219
Important consequence:
224
220
225
-
-event behavior is not owned by a single state system
226
-
- when debugging, inspect the action, listener, operation, repository, and store layer together
221
+
-persisted Event behavior is owned by TanStack Query; Redux owns only draft and interaction state
222
+
- when debugging, inspect the query key, cache utility, mutation lifecycle, and repository source together
227
223
228
224
## Styling Systems
229
225
@@ -334,6 +330,6 @@ Connect-later guardrail:
334
330
## What To Read Before Editing
335
331
336
332
- Auth/session issue: read session provider, user provider, router loaders.
337
-
- Event refresh issue: read the SSE hooks (which invalidate query scopes), the `useXEventsQuery` read hooks, `event.query.options.ts`, and the mutation operations (which invalidate on success).
333
+
- Event refresh issue: read the SSE hooks (which invalidate query scopes), the `useXEventsQuery` read hooks, `event.query.options.ts`, and `useEventMutations.ts`(which invalidates after settlement).
338
334
- Offline issue: read storage adapter and migration runner.
339
335
- Rendering issue in day/week: start at the route view, then its hooks.
0 commit comments