nestjs · Easy · fallback policy
A production API needs a fallback target resolution repair at its service boundary. A React dialog can close because the user confirms, cancels, presses Escape, or the trigger disappears after navigation. The current reducer always restores focus to the original trigger, including when it is no longer mounted.
Task
Implement the fallback target resolution contract used by the supplied HTTP adapter. Choose one safe focus target from the close reason and the currently mounted element IDs.
Contract
Input is {triggerId,fallbackId,closeReason,mountedIds}. Return {focusId,announce}. Prefer a mounted trigger, then a mounted fallback, otherwise null.
Acceptance criteria
- Never return an unmounted element.
- Use the same target for confirm, cancel and Escape.
- Return a concise close announcement.
- Do not make focus depend on object identity.
- Return a deterministic JSON-serializable result for the HTTP adapter.
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