Vue · Medium · Async State
A support agent uses the Projects page to find the project named in a customer ticket. Each change to the search field requests matching projects from the supplied API. If the agent types "api" and then "web", the slower response for "api" can currently replace the results for "web", making the page show projects that no longer match the field. The screen, API fixture and result rows are provided; your change belongs in the component that coordinates requests and visible search state.
Task
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.
Contract
- 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. - User action: The user changes the Search projects text. The initial screen starts with an empty query.
- 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. - Timing guarantees: API operations may resolve or reject in any order, even after cancellation. The fixture controls completion order; no real network is used.
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.
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.
- Use the injected fake API, not hard-coded results. Abort obsolete work and guard against promises settling after abort.
- No outbound network, paid API or browser permission is needed. New files are not submitted by the embedded widget.
Editable files
src/ProjectApp.vue— Repair the component state, lifecycle and API coordination.src/ProjectRows.vue— Provided row rendering; preserve identity, accessibility and button semantics.src/helpers.js— Optional pure helpers; not a replacement for framework lifecycle handling.tests/candidate.test.js— Add DOM-level regression tests using fixture(t), deferred() and assert.