[menubar] Make touch-click cooldown test deterministic with fake timers - #5393
Merged
michaldudak merged 1 commit intoJul 31, 2026
Merged
Conversation
The "ignores a delayed touch click immediately after focus opens another menu" test raced the 300ms allowTouchToClose cooldown started by the focus-open against real wall-clock time: the act(focus) flush alone consumes ~50ms, so under load the "immediate" touch click could arrive after the cooldown expired and close the menu, failing the assertion. Freeze timers before the focus so the cooldown cannot expire early, and advance past its expiry explicitly instead of sleeping 310ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
michaldudak
force-pushed
the
claude/distracted-bhaskara-f8ae66
branch
from
July 31, 2026 07:58
873ded3 to
4a7fd27
Compare
commit: |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size
PerformanceTotal duration: 1,467.09 ms -48.87 ms(-3.2%) | Renders: 78 (+0) | Paint: 2,309.50 ms -68.77 ms(-2.9%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
michaldudak
marked this pull request as ready for review
July 31, 2026 09:21
michaldudak
requested review from
atomiks,
colmtuite,
flaviendelangle and
jjenzz
as code owners
July 31, 2026 09:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a pre-existing, load-sensitive flake in
Menubar.test.tsxnoticed during the review of #5378: the "ignores a delayed touch click immediately after focus opens another menu" test failed in 2 of 3 full jsdom runs on a loaded machine, while passing in isolation.The race
Focusing the edit trigger opens its menu with reason
trigger-focus, which starts a 300ms wall-clock cooldown (allowTouchToCloseTimeoutinMenuRoot.tsx) during which touch clicks must not close the menu. The test then fired an "immediate" touch click and asserted the menu stayed open — but that click isn't actually immediate: instrumentation shows theact(focus)flush alone consumes ~51ms andfindByTestIdanother ~6–13ms, i.e. 62–146ms of the 300ms budget even on a fast, idle machine. Under full-suite load, a scheduler stall or GC pause pushes the gap past 300ms; the cooldown expires, the touch click closes the menu, and the assertion fails withexpected null not to be null.Injecting a 310ms stall between the focus-open and the first click reproduced the exact failure signature deterministically.
The fix
vi.useFakeTimers()before the focus that starts the cooldown, so no wall-clock time can elapse before the first touch click regardless of machine load.wait(310)withvi.advanceTimersByTime(310)insideactto expire the cooldown explicitly.finallybefore the closing click and itswaitFor, following the existing fake-timer pattern used elsewhere in the repo.Verification
Menubar.test.tsxfile: 3/3 repeat runs green; full jsdom suite green (328 files / 7465 tests).eslintandprettierclean.🤖 Generated with Claude Code