-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
feedStore.toSummary() calls useEndpointStore.getState().endpoints — a point-in-time snapshot with no subscription. If endpoints are subsequently created, updated, deleted, or reloaded on project switch, the endpoint_type on every already-stored RequestSummary goes stale. Components rendering feed rows show incorrect type badges until the feed is also reloaded.
- The stores are loaded in parallel on project switch (
AppShell.tsxcalls all data loaders inPromise.all) - No listener exists to sync feedStore when endpoints change
- Store tests mock each store independently, completely missing the integration bug
Proposed Interface
Zero caller changes. The fix adds ~15 lines to feedStore.ts:
- Add
endpoint_id: string | nulltoRequestSummarytype (preserve it throughtoSummary()instead of discarding after lookup) - Add a
_reEnrich()internal action that re-mapsendpoint_typefrom currentendpointStore.endpoints - Add a module-level Zustand subscription:
useEndpointStore.subscribe(
(s) => s.endpoints,
() => useFeedStore.getState()._reEnrich(),
{ equalityFn: shallow }
)_reEnrich implementation:
_reEnrich: () => {
const endpoints = useEndpointStore.getState().endpoints
set((s) => {
const requests = s.requests.map((req) => {
const type = req.endpoint_id
? (endpoints.find((e) => e.id === req.endpoint_id)?.endpoint_type ?? null)
: null
return type !== req.endpoint_type ? { ...req, endpoint_type: type } : req
})
return { requests, filtered: applyFilters(requests, get().filters) }
})
}Components continue reading useFeedStore(s => s.filtered) unchanged.
Dependency Strategy
- Category: In-process (both stores are in-memory Zustand)
feedStorealready importsuseEndpointStore(line 3) — no new dependency introduced- Subscription is one-directional: endpointStore -> feedStore
endpointStoredoes not knowfeedStoreexists- Identity guard preserves object identity for unchanged rows, keeping
memo()effective
Testing Strategy
- New boundary tests: Seed requests with
endpoint_id, calluseEndpointStore.setState({ endpoints: [...] }), assertfilteredrows have updatedendpoint_type. Test the race condition: load endpoints after feed, verify enrichment fires. - Old tests to delete: None — existing feedStore tests don't test
toSummary()enrichment - Test environment: Standard Vitest with Zustand stores
Implementation Recommendations
- The module should own the join between request
endpoint_idand endpointendpoint_type - It should hide the subscription wiring, the re-enrichment trigger, and the identity-preserving update
- It should expose the same
filtered/requestsinterface callers already use - The
endpoint_idfield addition toRequestSummaryis the only type change - The
request-loggedevent path (addRequest) still callstoSummary()at event time, which is correct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels