Repository navigation
Description
Summary
src/components/atoms/Modal/Modal.focus-opener.test.tsx fails about one run in four on main (a5f3b29): 3 of 12 runs alone, and 2 of 4 runs of the full lane. The failure is expected undefined to be <button id="elsewhere">, meaning no focus() call had been made when the assertion ran. That reddens the lean gate and CI's test:run on any PR at random.
The cause is timing in the spec, not the hook. Radix's FocusScope returns focus on unmount inside a setTimeout(…, 0) (node_modules/@radix-ui/react-focus-scope/dist/index.mjs:132, v1.3.1). That timer dispatches the unmount auto-focus event, which reaches useOpenerRestore's restoreFocus and its opening.focus() (src/hooks/use-opener-restore.ts:113). The spec's close() awaits one act(), which flushes React work and microtasks but not a macrotask, so the assertion sometimes runs before the timer fires.
Approach
Modal.focus-opener.test.tsx: makeclose()(lines 101–109) also flush one macrotask before it returns, for exampleawait act(() => new Promise((resolve) => setTimeout(resolve, 0))). An alternative is to assert withvi.waitFor(() => expect(asked.at(-1)).toBe(elsewhere)). Measured locally, the first form took the spec from 3 of 12 failing to 0 of 15.Modal.focus.test.tsx: apply the same fix. It has the same shape:await close(host)and then an immediateexpect(asked.at(-1)).toBe(opener)(lines 127–129), so it races the same timer.- Docblock: re-measure the "one dialog per FILE" rule in
Modal.focus.test.tsx's docblock once the timer is awaited. It blames cross-case teardown for failures of one in five and one in eight. That may have been this same timer. If several cases in one file now pass repeatedly, correct the docblock. The caller-wins case thatModal.focus-opener.test.tsxnotes as missing (lines 125–129) could then live beside the others. If they still fail, leave the rule and its measurement as they are.
Acceptance criteria
-
Modal.focus-opener.test.tsxandModal.focus.test.tsxwait for Radix's restore timer before asserting the focus call. - Each spec passes 20 consecutive runs on its own and 5 consecutive full-lane runs.
- Each spec still fails when the
opening.focus()call inuseOpenerRestore.restoreFocusis removed. This checks the wait has not made either spec vacuous. - The "one dialog per FILE" docblock matches what the re-measurement shows.
Verification checklist
-
for i in $(seq 20); do pnpm test:run src/components/atoms/Modal/Modal.focus-opener.test.tsx src/components/atoms/Modal/Modal.focus.test.tsx || break; donefinishes with no failure. -
pnpm test:runpasses 5 times in a row. - With
opening.focus()commented out insrc/hooks/use-opener-restore.ts, both specs fail. Restore it afterwards. -
.claude/skills/pr-prep/check.shpasses.
Notes
- Found while running the lean gate for style(ui): one type scale, one 24px panel edge and one corner rule #471, which does not touch either spec. It failed there and on an untouched
maincheckout. - Both specs came in with feat(a11y): the atlas widget can be used with a keyboard and a screen reader #435 (The atlas widget can be used with a keyboard and a screen reader #432's keyboard and screen-reader work).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
Ardnived commentedon Nov 24, 2026
@sydevs-bot implement
sydevs-dispatcher commentedon Nov 24, 2026
🤖 no session running
approved by Ardnived
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
docs(testing): tighten the retired one-dialog rule to its warning