+
Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Conversation

clintcs
Copy link
Collaborator

@clintcs clintcs commented Jul 24, 2025

🚀 Description

Patch

Menu no longer activates the wrong Option on open when Menu's containing block isn't the document.

📋 Checklist

  • I have followed the Contributing Guidelines.
  • I have added tests to cover new or updated functionality.
  • I have added or updated Storybook stories.
  • I have localized new strings.
  • I have followed the ARIA Authoring Practices Guide or met with the Accessibility Team.
  • I have included a changeset.
  • I have scheduled a design review.
  • I have reviewed the Storybook and Visual Test Report links below.

🔬 Testing

  1. Navigate to Menu 's Overview page in Storybook.
  2. Place your mouse just above Menu's target.
  3. Tab to Menu's target.
  4. Press Space to open Menu.
  5. Verify the first Option is active.

As an aside, the reason the issue was reproducible in Storybook is because Storybook wraps our components in a <div> that's styled with transform: scale(1)—giving Menu a containing block that's something other than the document.

You'll no longer be able to reproduce the issue on main if remove transform: scale(1) from that <div>.

Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: 69d08fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@crowdstrike/glide-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@clintcs clintcs force-pushed the fix-menu-activating-wrong-option-on-open branch 2 times, most recently from 728ab38 to 7e32113 Compare July 24, 2025 19:08
@clintcs clintcs changed the title Fix Menu activating wrong option on open Fix Menu activating the wrong option on open Jul 24, 2025
@clintcs clintcs force-pushed the fix-menu-activating-wrong-option-on-open branch 16 times, most recently from 51cf163 to a625f52 Compare July 25, 2025 13:44
padding-block-end: 0;
padding-block-start: var(--glide-core-spacing-base-xxxs);
padding-inline: var(--glide-core-spacing-base-xxxs);
position: absolute;
Copy link
Collaborator Author

@clintcs clintcs Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A leftover from Menu's pre-Popover days. Unnecessary given it's now using the Popover API.


host.open = true;
await aTimeout(0); // Wait for Floating UI
await requestIdleCallback(); // Wait for Floating UI
Copy link
Collaborator Author

@clintcs clintcs Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using aTimeout(0) to wait for Floating UI has always bothered me because there's no guarantee that Floating UI takes no more than a tick—especially in CI, which runs weaker hardware.

Since I introduced sub-Menus into Menu, we've seen this inherent issue with aTimeout(0) play out because sub-Menus create additional Floating UI work that, all together, sometimes take more than a tick to complete.

Waiting for the browser to become idle seems like the best way to wait for Floating UI in tests without components having to expose something (for example, a pseudo-private field that's a Promise) specifically for tests to wait on.

// `sendMouse()` is just a thin abstraction over Playwright's equivalent API. So
// the ultimate cause is likely Playwright or Chromium's DevTools Protocol, which
// Playwright relies on. It's that or I'm missing something obvious. Either way,
// it was time to move on.
Copy link
Collaborator Author

@clintcs clintcs Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Narrator: "He was missing something obvious."

Or at least it appears that way. I've gotten nothing but green builds after switching to requestIdleCallback() (below). I previously switched from await aTimeout(0) to a programmatic click() because I was reluctant to pass an even more arbitrary number to aTimeout().

But, it turns out, click() didn't make these tests less flaky because of something to do with sendMouse()—like I thought. Instead, it made these tests less flaky seemingly because it's synchronous and thus faster than sendMouse().

A programmatic click being faster, combined with the timeout on line 235, gave Floating UI just enough time to recalculate Menu's position—allowing the assertions below to succeed.

I wrote a short story below that'll give you more context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Green builds:

image

Copy link
Collaborator Author

@clintcs clintcs Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a followup, I'll replace uses of aTimeout(0) (at least ones used to wait for Floating UI) throughout the codebase with requestIdleCallback().

Tests that use requestIdleCallback() will be slightly slower, because waiting for the browser to become idle takes longer than a single tick. But our tests should be far less flaky—if they're flaky at all. Or at least that's the idea. Time will tell.

@clintcs clintcs force-pushed the fix-menu-activating-wrong-option-on-open branch 3 times, most recently from 06a6e2b to 82687cd Compare July 25, 2025 14:31
@clintcs clintcs force-pushed the fix-menu-activating-wrong-option-on-open branch from 82687cd to 69d08fe Compare July 25, 2025 14:37
@clintcs clintcs marked this pull request as ready for review July 25, 2025 14:42
@clintcs clintcs requested a review from danwenzel as a code owner July 25, 2025 14:42
@clintcs clintcs added this pull request to the merge queue Jul 25, 2025
Merged via the queue into main with commit b8fa589 Jul 25, 2025
29 checks passed
@clintcs clintcs deleted the fix-menu-activating-wrong-option-on-open branch July 25, 2025 15:44
@github-actions github-actions bot mentioned this pull request Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载