Skip to content

[menubar] Make touch-click cooldown test deterministic with fake timers - #5393

Merged
michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/distracted-bhaskara-f8ae66
Jul 31, 2026
Merged

[menubar] Make touch-click cooldown test deterministic with fake timers#5393
michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/distracted-bhaskara-f8ae66

Conversation

@michaldudak

Copy link
Copy Markdown
Member

Fixes a pre-existing, load-sensitive flake in Menubar.test.tsx noticed 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 (allowTouchToCloseTimeout in MenuRoot.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 the act(focus) flush alone consumes ~51ms and findByTestId another ~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 with expected 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

  • Enable 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.
  • Replace the fixed wait(310) with vi.advanceTimersByTime(310) inside act to expire the cooldown explicitly.
  • Restore real timers in a finally before the closing click and its waitFor, following the existing fake-timer pattern used elsewhere in the repo.

Verification

  • The fixed test passes with the same injected 310ms wall-clock stall that previously guaranteed failure.
  • Full Menubar.test.tsx file: 3/3 repeat runs green; full jsdom suite green (328 files / 7465 tests).
  • eslint and prettier clean.

🤖 Generated with Claude Code

@michaldudak michaldudak added test component: menubar Changes related to the menubar component. labels Jul 31, 2026
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
michaldudak force-pushed the claude/distracted-bhaskara-f8ae66 branch from 873ded3 to 4a7fd27 Compare July 31, 2026 07:58
@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

commit: 4a7fd27

@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 873ded3
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a6c555d0154770008cb8ea4
😎 Deploy Preview https://deploy-preview-5393--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 31, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

Total 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.

@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4a7fd27
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a6c55be4beffa00086ee668
😎 Deploy Preview https://deploy-preview-5393--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak
michaldudak marked this pull request as ready for review July 31, 2026 09:21
@michaldudak
michaldudak merged commit 3c55b15 into mui:master Jul 31, 2026
23 checks passed
@michaldudak
michaldudak deleted the claude/distracted-bhaskara-f8ae66 branch July 31, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: menubar Changes related to the menubar component. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant