Skip to content

fix(DismissableLayer): drop stale deferred click listener on inside pointerdown - #2892

Merged
zernonia merged 1 commit into
unovue:v2from
kevinpickett:fix/dismissable-layer-stale-touch-click
Aug 26, 2026
Merged

zernonia merged 1 commit into
unovue:v2from
kevinpickett:fix/dismissable-layer-stale-touch-click

Conversation

@kevinpickett

@kevinpickett kevinpickett commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Fixes #2891

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

On touch devices usePointerDownOutside defers the pointerDownOutside dispatch for an outside pointerdown to a one-shot document click listener. When that touch turns into a scroll or drag, no click follows and the listener stays armed. The isLayerExist(...) early return for inside and nested-layer targets skipped the cleanup that runs for other inside pointerdowns, so the click of 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 pending click listener before the inside-layer early return.

Changes:

  • DismissableLayer/utils.ts: drop the deferred click listener at the top of the isLayerExist branch (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 on v2 without the fix and pass with it; the existing outside tap-then-click case still dismisses.

Resolves #2891

📸 Screenshots (if appropriate)

n/a

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly. (no docs change needed)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where canceled touch taps could leave a stale outside-click handler active.
    • Tapping inside a nested or current layer no longer causes unexpected dismissal.
    • Later completed taps outside the layer continue to dismiss it as expected.

…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.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7179833b-663a-4433-ab97-546b1434971c

📥 Commits

Reviewing files that changed from the base of the PR and between 35dde22 and aeda352.

📒 Files selected for processing (2)
  • packages/core/src/DismissableLayer/DismissableLayer.test.ts
  • packages/core/src/DismissableLayer/utils.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change removes a pending deferred document click listener when a pointerdown occurs inside a dismissable layer. Regression tests cover cancelled touch taps with nested layers, the current layer, and later completed outside taps.

Changes

DismissableLayer touch handling

Layer / File(s) Summary
Deferred click cleanup and regression coverage
packages/core/src/DismissableLayer/utils.ts, packages/core/src/DismissableLayer/DismissableLayer.test.ts
The inside-layer pointerdown path removes the pending document click listener. Tests verify that cancelled outside touches do not dismiss nested or current layers on a later inside tap, while a completed outside tap still emits the expected events.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to aeda3

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: benjamincanac, zernonia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: removing a stale deferred click listener after an inside pointerdown.
Linked Issues check ✅ Passed The changes address issue #2891 by removing the pending click listener for inside and nested-layer pointerdowns, adding regression tests for cancelled outside touches, and preserving dismissal for com…
Out of Scope Changes check ✅ Passed All changes are directly related to the stale deferred click listener bug. The utility fix and regression tests remain within the linked issue scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Full details: Linked Issues check

Explanation

The changes address issue #2891 by removing the pending click listener for inside and nested-layer pointerdowns, adding regression tests for cancelled outside touches, and preserving dismissal for completed outside taps.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2892

commit: aeda352

@zernonia
zernonia merged commit f80e7f0 into unovue:v2 Aug 26, 2026
7 checks passed
zernonia pushed a commit that referenced this pull request Sep 4, 2026
…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
zernonia added a commit that referenced this pull request Sep 4, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DismissableLayer dismisses on the next tap inside after a cancelled touch outside (stale deferred click listener)

2 participants