Skip to content

fix(DismissableLayer): ignore outside pointerdown while not present - #2863

Merged
zernonia merged 2 commits into
unovue:v2from
benjamincanac:fix/dismissable-layer-present-pointerdown
Aug 13, 2026
Merged

zernonia merged 2 commits into
unovue:v2from
benjamincanac:fix/dismissable-layer-present-pointerdown

Conversation

@benjamincanac

@benjamincanac benjamincanac commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Reported downstream in nuxt/ui#6797.

❓ 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, usePointerDownOutside doesn't dispatch on pointerdown, it defers to the next click so 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 while present was false, so it captured the pointerdown of the tap that opens it. By the time that tap's click fired 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.present guard in the handler catches it. Touch never hits that guard.

Passing present as the composable's enabled means the listener isn't registered at all while hidden, and the existing setTimeout(0) before attaching covers the tick where the layer becomes present.

useFocusOutside takes the same enabled argument but is deliberately left alone here: it also gates onBlurCapture, so isFocusInsideDOMTree would stay stuck at true when focus leaves a hidden layer, and a later outside focus would be read as inside.

📸 Screenshots (if appropriate)

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where showing a dismissible layer after a touch interaction could incorrectly trigger outside dismissal.
    • Touch interactions outside the layer now correctly emit outside-pointer and dismissal events.
    • Hidden but mounted layers no longer respond to deferred touch events.

@coderabbitai

coderabbitai Bot commented Aug 10, 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: 24e10d32-69a0-410a-9780-635fff79cfc7

📥 Commits

Reviewing files that changed from the base of the PR and between 800fd0c and b49512e.

📒 Files selected for processing (1)
  • packages/core/src/DismissableLayer/DismissableLayer.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/DismissableLayer/DismissableLayer.test.ts

📝 Walkthrough

Walkthrough

DismissableLayer now disables outside-pointer monitoring while hidden. A regression test covers deferred touch events during opening and verifies dismissal from a later outside tap.

Changes

DismissableLayer touch handling

Layer / File(s) Summary
Present-gated pointer monitoring and regression coverage
packages/core/src/DismissableLayer/DismissableLayer.vue, packages/core/src/DismissableLayer/DismissableLayer.test.ts
usePointerDownOutside now uses props.present as its enabled condition. The test verifies that the opening touch does not dismiss the layer and that a later outside touch emits pointerDownOutside and dismiss.

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

Possibly related PRs

  • unovue/reka-ui#2790: Both changes address deferred touch handling in DismissableLayer; this PR gates monitoring with props.present.
🚥 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 main fix: ignoring outside pointer events when DismissableLayer is not present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: b49512e

@MILLERMARRU MILLERMARRU left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@zernonia

Copy link
Copy Markdown
Member

LGTM @benjamincanac ! Nicely done 😁

@zernonia
zernonia merged commit 099dab9 into unovue:v2 Aug 13, 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.

3 participants