react + express · Medium · request ownership
A browser and API disagree at the paged flow request ownership boundary. A search screen can request several pages for one query while the user changes the query. Late pages from the previous search currently append to the new result set.
Task
Repair the shared browser-to-service contract. Reduce request and response events into visible state where only the current search generation can commit rows.
Contract
Input is {events}. Events are search{id,query}, page{id,cursor,rows,nextCursor}, failure{id,message}. Return {query,rows,nextCursor,error}. A search starts a new generation and clears rows and errors.
Acceptance criteria
- Only events matching the latest search id may commit.
- Append pages in event order and deduplicate by row id.
- A current failure preserves committed rows and sets error.
- A stale failure changes nothing.
- 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