Repository navigation
feat(recruitment): make applicant switching reliable - #81
Conversation
Use URL selection and identity-keyed queries for applicant reviews. Keep late responses and saves attached to their original application, and separate proposed stage changes from cached server data.
ktirumal2006
left a comment
There was a problem hiding this comment.
All 31 existing tests passed locally. An additional focused hook test reproduced a stale-list race after saving a rating: the refreshed details contain the saved value, but the selected applicant data reverts when the older initial list response arrives. Please address the inline finding and add regression coverage before merging.
|
|
||
| async function refreshApplication(applicationId: string) { | ||
| // An initial detail read may predate the save; do not reuse its response. | ||
| await client.cancelQueries({ queryKey: keys.details(teamId, applicationId) }); |
There was a problem hiding this comment.
Could we also cancel the pending applications-list query before invalidating it?
I reproduced a race on commit 41fed7c with a focused hook test using controlled fetch responses: applicant details load while the initial list remains pending, a rating update successfully saves 5 stars, and the refreshed details return 5. When the initial list then resolves with the old value of 0, selected.stars becomes 0 because the list entry takes precedence over the details.
Invalidating the initially pending list reuses that request rather than fetching fresh data. Please ensure the older list response cannot replace the successfully saved value, and add a regression test covering this sequence.
There was a problem hiding this comment.
Youre right, i found that invalidating a query that has no data yet reuses the request already in flight (TanStack/query#8530), so the pre-save list request overwrote the saved rating. Stage changes had the same race.
Fixed in 9e9af4c by cancelling the list query before invalidating it, matching details. Added a regression test for this: it fails on 41fed7c and passes now. Also verified it in the real UI.
Invalidating a query only restarts its request when the query already has data, so a save during the initial board load reused the pre-save list request and its stale result overwrote the saved value. Cancel the list read before invalidating it, as already done for details. Also drop the cache clear on unmount: each reviewer/team session owns a discarded client, and the cleanup emptied the cache in StrictMode.
Switching applicants currently clears and reloads their information, briefly shows misleading empty states, and can let a late response display the previous applicant’s data.
This uses the existing React Router and TanStack Query setup so the URL owns selection and each applicant’s requests stay separate. Back/Forward, refresh, and direct links work, recently viewed data is reused, and saves stay attached to the application they started on.
Loading, empty, and error states are separated. Resume links refresh automatically before expiry, with an “Open resume” fallback and retry on errors. Dragging proposes a stage change without modifying saved data before confirmation; cards stay in their saved position until the update succeeds.
No new dependencies or backend changes.
All 31 UI tests pass, including two focused checks for navigation/caching and stale responses. Also tested the real UI in Chrome with synthetic responses, delayed requests, retries, and a delayed rating save. Production authentication and resume performance remain unverified. Typecheck still reports 18 pre-existing errors outside this change.
Closes #72