react + fastify · Hard · cache lifecycle
A browser and API disagree at the shared query lifecycle boundary. Several panels subscribe to the same query. The current cache aborts the shared request when any panel unmounts and commits a late response after the final subscriber has gone.
Task
Repair the shared browser-to-service contract. Reduce subscribe, unsubscribe, resolve and reject events into cache state with reference-counted ownership.
Contract
Input is {events}. subscribe/unsubscribe carry key and subscriber; resolve/reject carry key and requestId. Return entries keyed by query with subscribers, status, value, error and aborted request IDs.
Acceptance criteria
- One pending request is shared per key.
- Unsubscribing one consumer keeps work alive for remaining consumers.
- The last unsubscribe aborts and invalidates the request.
- Late settlements from invalidated requests are ignored.
- Keep browser-visible state consistent with the canonical service result.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression