Repository navigation
fix(DismissableLayer): ignore outside pointerdown while not present - #2863
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesDismissableLayer touch handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
MILLERMARRU
left a comment
There was a problem hiding this comment.
Checked the actual mechanism in utils.ts rather than taking the deferred-touch claim on faith, and it matches exactly: pointerType === 'touch' skips handleAndDispatchPointerDownOutsideEvent() and instead registers a one-time click listener that fires it later, while the mouse branch calls it immediately. That confirms why the existing !props.present guard inside the handler catches the mouse case (event dispatched while still hidden) but not touch (event dispatched later, after present flipped).
Also checked the reasoning for deliberately not touching useFocusOutside the same way, since that's the part that would be easy to get wrong. onBlurCapture there is gated by the same enabled param and sets isFocusInsideDOMTree.value = false. If it were gated by present too, a blur that happens while the layer is hidden would be silently skipped, so isFocusInsideDOMTree would stay stuck at whatever it was before hiding. When the layer becomes present again and focus genuinely moves outside afterward, handleFocus's !isFocusInsideDOMTree.value check would still read the stale true and never dispatch. So leaving that composable alone is the correct call given the shape of its own state tracking, not an inconsistency.
Good regression test, the touch-specific pointerType property injection on a plain MouseEvent for jsdom is a reasonable way to hit the touch branch without a real PointerEvent.
|
LGTM @benjamincanac ! Nicely done 😁 |
…the registry Three fixes that shipped on v2 after the layer stack manager landed patched code the manager replaced, so they never reached v3: - #2863: outside-pointer subscribers now pass `() => props.present` as `enabled`. A hidden `unmountOnHide: false` layer no longer keeps a touch deferral alive and dismisses itself on the tap that opened it. - #2892: the inside-tree branch of `handlePointerDown` now cancels a pending touch deferral, so a scroll-cancelled outside tap cannot fire a stale `pointerDownOutside` on the next inside tap. - #2832: `layerStack` exports `hasBodyPointerEventsLock()` and `useBodyScrollLock` consults it before clearing body `pointer-events`, so releasing the last scroll lock no longer unlocks a modal layer that has no scroll lock of its own (#2784). And one bug specific to v3: layer ordering was read from a document-wide `querySelectorAll('[data-dismissable-layer]')`, which cannot see layers inside shadow roots, so two nested layers in one shadow root both indexed -1 and a pointerdown inside the child dismissed the parent. Ordering now comes from the manager's own registry, with composed containment checks. Subscribers that never register a stack layer (Editable) keep the previous document-order rule. Tests are ported from the v2 commits and adapted to `resetLayerStack()`; a shadow-root case covers the ordering fix. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu
… review (#2908) * fix(Label): forward attrs on the `#render` path Label kept Vue's default `inheritAttrs`, but `useRender`'s `#render` slot makes the component root a fragment, so class, id, aria-* and listeners passed by the consumer were silently dropped with an "Extraneous non-props attributes" warning. Mirror the `Primitive` compat shim: disable attr inheritance and fold `useAttrs()` into the props handed to `useRender`, so attrs reach the element exactly once on both the default and the `#render` path. Consumer listeners merge after Label's own, matching Vue's fallthrough order. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu * fix(RadioGroup): stop falling back to the item value for aria-label Port of #2861 onto the v3 shadow-DOM-aware lookup. The item value is not an accessible name, so `aria-label` now resolves only from an associated `[for]` label (or an explicit attribute) and is otherwise omitted. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu * test(DismissableLayer): make the dispatch benchmarks exercise the manager Two of the three benches never reached the code they claim to measure: the outside-pointerdown bench dispatched before subscribers armed (arming is a macrotask after registration), and the Escape bench dispatched a non-bubbling keydown on `document` while the shared listener lives on `window`. Both early-returned on every iteration. Mount and arm in `setup`, dispatch alone in the measured body, and bubble the keydown from the top layer element. Document what each bench measures and that only ratios against a v2 run are meaningful. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu * fix(Switch): run consumer listeners before the internal toggle The `useSwitch()` conversion bound the composable's `onClick`/`onKeydown` ahead of `$attrs` in one `mergeProps` call. `mergeProps` chains same-named listeners in argument order, so the internal toggle ran first and a consumer `@click` observed the post-toggle model, unlike v2 where `v-bind="$attrs"` preceded `@click`. Bind the composable's handlers as directives after `v-bind`, which restores v2 precedence on both axes: a consumer attribute still overrides the component's `role`/`aria-*`, and a consumer listener still runs first. The characterization tests now assert the order instead of only that both listeners fire. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu * fix(DismissableLayer): port v2 dismissal fixes and order layers from the registry Three fixes that shipped on v2 after the layer stack manager landed patched code the manager replaced, so they never reached v3: - #2863: outside-pointer subscribers now pass `() => props.present` as `enabled`. A hidden `unmountOnHide: false` layer no longer keeps a touch deferral alive and dismisses itself on the tap that opened it. - #2892: the inside-tree branch of `handlePointerDown` now cancels a pending touch deferral, so a scroll-cancelled outside tap cannot fire a stale `pointerDownOutside` on the next inside tap. - #2832: `layerStack` exports `hasBodyPointerEventsLock()` and `useBodyScrollLock` consults it before clearing body `pointer-events`, so releasing the last scroll lock no longer unlocks a modal layer that has no scroll lock of its own (#2784). And one bug specific to v3: layer ordering was read from a document-wide `querySelectorAll('[data-dismissable-layer]')`, which cannot see layers inside shadow roots, so two nested layers in one shadow root both indexed -1 and a pointerdown inside the child dismissed the parent. Ordering now comes from the manager's own registry, with composed containment checks. Subscribers that never register a stack layer (Editable) keep the previous document-order rule. Tests are ported from the v2 commits and adapted to `resetLayerStack()`; a shadow-root case covers the ordering fix. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu * test(Label, DismissableLayer): fix two new tests that failed in CI - Label: VTU's `trigger` cannot set `detail` on a UIEvent in jsdom (getter-only), so dispatch a real `MouseEvent` with `detail: 2`. - DismissableLayer shadow-root case: the child's outside subscriber arms on a macrotask scheduled during the re-render microtask, which was queued after the test's `sleep` timer. The first pointerdown then hit an unarmed subscriber and left `isPointerInside` set, so the outside pointerdown was treated as a cancelled inside press. Flush the render with `nextTick` before waiting for arming. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjAHnVc7rPjMzA2srYUtiu --------- Co-authored-by: Claude <noreply@anthropic.com>
🔗 Linked issue
Reported downstream in nuxt/ui#6797.
❓ Type of change
📚 Description
On touch,
usePointerDownOutsidedoesn't dispatch onpointerdown, it defers to the nextclickso the ~350ms tap delay can't replay events that should have been prevented.A layer that stays mounted while hidden (
unmountOnHide: false) was still listening whilepresentwasfalse, so it captured thepointerdownof the tap that opens it. By the time that tap'sclickfired the layer was present, the deferred handler ran, and it dismissed itself on the very interaction that opened it. On mouse there's no deferral, so the event is dispatched while the layer is still not present and the!props.presentguard in the handler catches it. Touch never hits that guard.Passing
presentas the composable'senabledmeans the listener isn't registered at all while hidden, and the existingsetTimeout(0)before attaching covers the tick where the layer becomes present.useFocusOutsidetakes the sameenabledargument but is deliberately left alone here: it also gatesonBlurCapture, soisFocusInsideDOMTreewould stay stuck attruewhen focus leaves a hidden layer, and a later outside focus would be read as inside.📸 Screenshots (if appropriate)
📝 Checklist
Summary by CodeRabbit