[popups] Scope queued focus cancellation to its target element#5293
Open
m2na7 wants to merge 1 commit into
Open
[popups] Scope queued focus cancellation to its target element#5293m2na7 wants to merge 1 commit into
m2na7 wants to merge 1 commit into
Conversation
m2na7
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
July 21, 2026 10:04
commit: |
Bundle size
PerformanceTotal duration: 1,289.07 ms +29.65 ms(+2.4%) | Renders: 78 (+0) | Paint: 2,010.98 ms +34.14 ms(+1.7%)
13 tests within noise — details Metric alarms
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. |
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 #5268
Summary
enqueueFocuskeeps a single module-level rAF handle and unconditionally cancels it on entry, so concurrent callers cancel each other's queued focus regardless of target. On keyboard-open of a roving-focus popup,FloatingFocusManager's initial-focus call cancels the option focus queued byuseListNavigation— the manager'sshouldFocusguard is designed to yield when focus has already moved inside the popup, but the module-level cancel kills the very frame that would move it, so the guard never gets the chance.Pending frames are now keyed per element (
WeakMap<FocusableElement, number>), so a caller only replaces its own target's pending focus. With that in place, the initial-focus guard observes the item focus and yields as designed. When the manager's initial-focus fallback resolves to a different element than the active item (any tabbable rendered before the items), the old code left focus permanently on that element and list navigation dead — the new hook-level test pins that case.useListNavigationretires its own previous queued request before queueing focus for another item, preserving the previous last-wins behavior for consecutive queued requests. Anulltarget is now a no-op instead of cancelling an unrelated caller's pending focus.The existing TODO in
useListNavigation.test.tsx("the animation frame callback fromenqueueFocussometimes kicking in after the click … causes flakeyness") describes the same mechanism.Behavior notes
AnimationFramescheduler was evaluated and deliberately left out: it changes timing under JSDOM's rAF stub and breaks four JSDOM-onlyFloatingFocusManagertests. [internal] Refactor: remove raw requestAnimationFrame #1901 also left this file's raw rAF in place.Tests
enqueueFocus.test.ts(new): the cancellation semantics unit-tested with faked frames — JSDOM's realcancelAnimationFramedoesn't cancel, so the suite runs onvi.useFakeTimers(). Two cases fail onmain(cross-element cancel,nullside effect); the rest pin the preserved behavior (same-element replacement, cancel-function guard,sync,shouldFocus), each verified to fail against a mutated implementation.useListNavigation.test.tsx: keyboard-open focuses the active item when the manager's initial focus targets another tabbable (fails onmain); consecutive queued requests skip intermediate items.