Express + React · Medium · Async State
The React screen and Express service already run separately. Their integration contains transport and state regressions. Prioritize tenant isolation and the service consistency boundary. Verify the user-visible result through the existing React client.
Task
Deliver one working browser-to-service flow, not two disconnected implementations. Deliver a search screen that keeps the results for the user’s latest query even when an older request finishes later, and clearly shows whether that latest search is loading, empty or failed. Repair tenant isolation and pagination as one consistent pipeline. Preserve existing authentication and error behavior.
Contract
- Browser — Starting data:
initialRowsis the supplied project list. Do not mutate it.ididentifies a project;titleis its visible name;archivedhides it from the active list.seatsis the available seat count;versionidentifies the last server version of that project. - Browser — User action: The user changes the Search projects text. The initial screen starts with an empty query.
- Browser — Provided search API:
api.list(query, {signal})returns a Promise of project rows. Pass the trimmed query and an AbortSignal. A successful result is the next project list. A failure is an error, not an empty successful result. - Browser — Timing guarantees: API operations may resolve or reject in any order, even after cancellation. The fixture controls completion order; no real network is used.
- API — Request:
GET /projectsreads the supplied project repository. Query parameters are optional. - API — Query parameters:
q— title text to search for. Default: empty string. Trim whitespace; maximum length: 80 characters.limit— number of rows requested. Default:20; allowed integers:1..50.offset— number of matching rows to skip. Default:0; allowed integers:0..10000. Numeric parameters must contain digits only. For example,1.5,-1andabcare invalid. - API — Authentication:
Authorization: Bearer fixture-alphaidentifies tenantalpha;fixture-bravoidentifies tenantbravo. The supplied authentication helper resolves the tenant. A query/body field is not an identity source. - API — Repository records: Each project has
id,title,tenant,archived,seatsandversion. The fixture provides the data. Use its repository; no external database is required. - Connecting the two layers:
web/src/api-client.jsis the browser-to-HTTP adapter.api.listreads the HTTP response’sitemsarray.api.reservemaps the HTTP receipt’sremainingfield to the component’sseatsfield.
Acceptance criteria
- Start the initial empty-query search and a new search whenever the query changes.
- Clear the previous error and show
Loadingwhile the current request is pending. - Cancel the superseded request.
- Only the latest request may replace the rows or show an error.
- Latest request succeeds: display its active rows and stop loading; an empty list shows
No projects. - Latest request fails: show
Search failedand stop loading. - An older success or error must not change the current screen.
- At component unmount, cancel outstanding work.
- Ignore later results; do not update a closed or disposed screen.
- Return HTTP
200with{total, items, nextOffset}. itemscontains only{id, title, seats, version}. Do not expose the internal tenant field.- Keep only the authenticated tenant’s non-archived projects.
- Match the title against the trimmed query without regard to letter case.
- Sort matching projects by ASCII ID before taking the requested page.
totalis the number of all matching projects before pagination, not the page length.- Skip
offsetmatches and return at mostlimititems. nextOffsetisoffset + items.lengthonly when another matching item remains; otherwise it isnull.- An exhausted page has
items: []andnextOffset: null, while keeping the fulltotal. - Invalid query: HTTP
400with{code: "INVALID_QUERY"}. - Missing or unknown bearer token: HTTP
401with{code: "UNAUTHORIZED"}. - URL-encode search text; it must not become extra query parameters.
- Reject failed HTTP responses with their status. Do not hide errors as an empty successful list.
Constraints
- At most 200 rows; IDs are unique ASCII strings and seats are non-negative integers. Input props must not be mutated.
- Keep the Search projects label, data-id row identity and accessible status messages.
- At most 10000 projects in the repository; query length at most 80; page size at most 50.
- Use the supplied repository and authenticated tenant resolver. No external database, network service or production credential is needed.
- Directory reads must not mutate stored records or expose the internal tenant field.
- All services run inside the test process on loopback. No external deployment, database or cloud account is required.
Editable files
web/src/ProjectApp.jsx— Repair the component state, lifecycle and API coordination.web/src/ProjectRows.jsx— Provided row rendering; preserve identity, accessibility and button semantics.web/src/helpers.js— Optional pure helpers; not a replacement for framework lifecycle handling.web/tests/candidate.test.js— Add DOM-level regression tests using fixture(t), deferred() and assert.server/src/app.js— Framework router/controller, middleware and error response integration.server/src/service.js— Repair filtering/pagination or the reservation consistency boundary.server/src/helpers.js— Optional helpers; import from service when needed.server/tests/candidate.test.js— Add the required regression tests here using fixture(t), assert and node:test.web/src/api-client.js— Repair URL encoding, error propagation and response DTO mapping.integration/candidate.test.js— Add cross-layer regressions; reuse the local integration fixture.