Repository navigation
fix(DismissableLayer): drop stale deferred click listener on inside pointerdown - #2892
Conversation
…ointerdown On touch devices a pointerdown outside a layer defers the pointerDownOutside dispatch to the next click. When that tap becomes a scroll or drag no click follows, so the one-shot listener stays armed. The isLayerExist early return for inside and nested-layer targets skipped the cleanup that Radix performs in its inside-tree branch (radix-ui/primitives#2171), so the next tap inside the layer fired the stale listener and dismissed it. Remove the pending click listener before the inside-layer early return.
|
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 (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change removes a pending deferred document ChangesDismissableLayer touch handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This is a localized bug fix that removes a stale deferred click listener and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Linked Issues checkExplanation The changes address issue ✨ Finishing Touches🧪 Generate unit tests (beta)
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: |
…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
Fixes #2891
❓ Type of change
📚 Description
On touch devices
usePointerDownOutsidedefers thepointerDownOutsidedispatch for an outsidepointerdownto a one-shot documentclicklistener. When that touch turns into a scroll or drag, noclickfollows and the listener stays armed. TheisLayerExist(...)early return for inside and nested-layer targets skipped the cleanup that runs for other inside pointerdowns, so theclickof the next tap inside the layer fired the stale listener and dismissed the layer.This mirrors the inside-tree branch in Radix's
usePointerDownOutside(radix-ui/primitives#2171): remove the pendingclicklistener before the inside-layer early return.Changes:
DismissableLayer/utils.ts: drop the deferredclicklistener at the top of theisLayerExistbranch (one line plus a comment).DismissableLayer.test.ts: two regression tests (tap inside the layer itself, and inside a nested layer, after a cancelled touch outside). Both fail onv2without the fix and pass with it; the existing outside tap-then-click case still dismisses.Resolves #2891
📸 Screenshots (if appropriate)
n/a
📝 Checklist
Summary by CodeRabbit