Skip to content

fix(DismissableLayer): share one ref-counted owner for body pointer-events - #2987

Merged
zernonia merged 2 commits into
unovue:v2from
SDIjeremy:fix/body-pointer-events-owner
Oct 5, 2026
Merged

zernonia merged 2 commits into
unovue:v2from
SDIjeremy:fix/body-pointer-events-owner

Conversation

@SDIjeremy

@SDIjeremy SDIjeremy commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2867

What happens

useBodyScrollLock and DismissableLayer both write document.body.style.pointerEvents, and each keeps its own idea of what to restore. #2832 closed one direction, where the scroll lock's reset cleared a layer's lock. The two edges it listed as out of scope are still open on v2:

  1. A layer mounts under an active scroll lock. DismissableLayer saves whatever the body has at that moment as originalBodyPointerEvents. That's the lock's 'none', and the layer writes it back on its final restore. Once both have closed, the body is stuck at pointer-events: none until a reload.
  2. A layer releases while a scroll lock still holds. The layer's restore doesn't check for active scroll locks, so it clears the lock's 'none' while the lock is still meant to hold it.

A deterministic real-world trigger for edge 1 is a modal Dialog that's open in the SSR render (details in #2867 (comment)). Hydration runs outside a scheduler flush, so DialogOverlayImpl's scroll-lock nextTick sets 'none' before the content's layer registers. The layer saves 'none'. Closing the dialog by Escape, an outside click, or the close button leaves the page unclickable. The same dialog opened client-side is fine.

The fix

This is the shared, ref-counted owner that #2832 and #2867 both suggested. A small internal module, shared/bodyPointerEvents.ts, keeps a set of owners per document in a WeakMap<Document, …>:

  • acquireBodyPointerEvents(doc, owner): the first acquire saves the body's current inline value. Every acquire sets 'none'.
  • releaseBodyPointerEvents(doc, owner): the last release restores the saved value. A release from an owner that never acquired is a no-op.

Both writers now go through it:

  • useBodyScrollLock acquires where it used to set 'none', keeping the same nextTick timing. It releases in resetBodyStyle() instead of writing ''. The whole lock stack counts as one owner. fix(DismissableLayer): keep body pointer-events locked when the last scroll lock releases #2832's registry check in resetBodyStyle() is no longer needed, so it's removed, and shared/ no longer imports DismissableLayer/context.
  • DismissableLayer acquires with its element as the owner when a disableOutsidePointerEvents layer registers, and releases in the same onCleanup. This replaces context.originalBodyPointerEvents. The layer registry, the stack order, and the per-layer pointer-events: auto / none styling are unchanged.

Since the owner doesn't care who comes or goes first, both edges close. A page's own inline pointer-events value now survives a scroll-lock cycle too; the old reset overwrote it with ''. Layers inside an iframe also get their own entry, because the old shared originalBodyPointerEvents mixed documents. No public exports change.

Tests

  • Edge 1: a scroll lock engages, then a modal layer mounts under it. Both release orders end with the body restored. Lock-first was red before this change.
  • Edge 2: a layer mounts, then a lock engages, then the layer releases first. The body stays 'none' until the lock releases. Red before.
  • Page value: a page-defined inline pointer-events: auto is preserved through a lock + layer cycle and a lock-only cycle. Red before.
  • Hydration: Dialog.ssr.test.ts server-renders an open modal Dialog (overlay + content), hydrates it, closes it, and expects the body restored. Red before. The scroll lock is stubbed only for the server render, because in jsdom it would otherwise engage and stay held. On a real server it's inert.
  • Owner unit tests: last-release restore, duplicate acquire, release from a non-owner, re-saving after a full release, and per-document isolation.
  • All existing tests pass unchanged, including fix(DismissableLayer): keep body pointer-events locked when the last scroll lock releases #2832's handoff suite and the [Bug]: Dropdown inside dialog strips pointer-events style from body #2674 nested/sibling suites.
  • Full core suite: 111 files / 2703 tests green (test:coverage). pnpm --filter reka-ui build (vue-tsc + tsdown), eslint ., and size all pass.

Notes

Summary by CodeRabbit

  • Bug Fixes

    • Improved pointer-event handling when dialogs, modal layers, or scroll locks overlap. The page remains blocked until all locks are released, then restores its previous behavior.
    • Improved handling when locks are reapplied and across separate documents.
  • Tests

    • Added coverage for dialog hydration and overlapping lock behavior.

…vents

useBodyScrollLock and DismissableLayer both wrote body.style.pointerEvents.
A layer mounting under an active scroll lock saved its 'none' as the
original and wrote it back on final restore, and a layer's restore could
clear a lock that was still held. Both now acquire and release a shared
per-document owner: the first acquirer saves the original value and the
last release restores it.

Fixes unovue#2867
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: unovue/reka-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a9718748-1a44-4e5f-bf75-86f826b98806
📥 Commits

Reviewing files that changed from the base of the PR and between 40278cb and 56b5509.

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

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

A shared per-document lock now coordinates body pointer-events ownership between useBodyScrollLock and DismissableLayer. Tests cover owner release behavior, style restoration, separate documents, and hydration of an initially open Dialog.

Changes

Body pointer-events ownership

Layer / File(s) Summary
Shared per-document ownership
packages/core/src/shared/bodyPointerEvents.ts, packages/core/src/shared/bodyPointerEvents.test.ts
The shared helper tracks owners and the original body style per document. Tests cover multiple owners, duplicate acquisition, unregistered releases, reacquisition, and separate documents.
Scroll-lock and modal-layer integration
packages/core/src/DismissableLayer/DismissableLayer.vue, packages/core/src/DismissableLayer/context.ts, packages/core/src/shared/useBodyScrollLock.ts, packages/core/src/DismissableLayer/DismissableLayer.test.ts, packages/core/src/Dialog/Dialog.ssr.test.ts
Both mechanisms use the shared helper to acquire and release ownership. Tests cover either release order, original style restoration, repeated lock cycles, and Dialog SSR hydration.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 56b55

The shared lock restores body pointer-events after owners release. No change introduced here has been shown to block merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 40278

The shared owner reduces conflicting style resets without adding privileges or turning UI interaction controls into authorization controls. No introduced security attack path was established. Moving an already-mounted layer between documents remains an unverified lifecycle edge case.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed sink is body CSS pointer-events, so its direct exposure is page-wide pointer interaction within the selected document. The helper isolates document ownership, although the scroll-lock consumer still selects the global document. These writes do not establish authority over another origin, service, tenant, or data store.

Trust Boundaries and Controls

  • inferred — The traced control flow remains application-selected modal interaction state and browser dismissal events leading to local DOM styles. Exact-owner membership prevents one cooperating participant from releasing another participant's share; it is coordination within the same JavaScript environment, not an authorization or sandbox boundary.

Resilience and Maintainability Implications

  • inferred — Adopting the same mounted layer element into another document without changing the watched state would not reacquire ownership there. Cleanup retains the original acquisition document. Whether live adoption is supported, or whether this behavior differs from base, is unresolved; it is not established as a PR-introduced security regression.
🚥 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 describes the main change: shared, ref-counted ownership of body pointer-events for DismissableLayer.
Linked Issues check ✅ Passed [#2867] The reviewed implementation uses a shared per-document owner for useBodyScrollLock and DismissableLayer. It restores the original inline value only after the last owner releases. The repor…
Out of Scope Changes check ✅ Passed All reported changes support [#2867]. The shared owner, integration changes, and regression tests address the pointer-events ownership conflict. The changes since the previous review are comment-only.…
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 5 functions across 6 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 Oct 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 56b5509

@zernonia
zernonia merged commit 1451c7a into unovue:v2 Oct 5, 2026
7 of 8 checks passed
zernonia added a commit that referenced this pull request Oct 5, 2026
Brings 139 v2 commits onto v3, including the Toast manager, Field / Form /
TagGroup, the NumberField props, vitest 5 with browser mode, and the 2.11.0
release fixes.

v2 fixes re-implemented on v3's composables:
- Tabs: respect `defaultPrevented` on trigger mousedown / keydown (useTabs)
- Popover: `aria-controls` only while open (usePopover)
- Menu: read `currentTarget` before awaiting in the item focus handler
- Tooltip: track a replaced trigger element; listen for TOOLTIP_OPEN on document
- Checkbox: group `max` and Field participation (useCheckbox, useCheckboxGroup)
- ContextMenu: controlled `open` through useControllableState
- DatePicker: same-day guard combined with the `date-select` close reason
- Drawer: trigger toggles; Combobox: `present`-aware lock and aria-hidden
- DismissableLayer: layer root counts as inside, cross-realm element check,
  and iframe documents attach to the shared layer stack listeners
- FocusScope: orphan check uses composed containment

Kept v3's body pointer-events handling rather than v2's shared owner (#2987);
the three tests for that gap are marked `it.fails` until #2822.

Also: ported the DismissableLayer benchmark to the vitest 5 fixture API, moved
v2-added `data-state` literals onto the shared helpers, updated Rating /
HoverCard / usePopover tests for v3 vocabulary and jsdom's getter-only event
fields, and made two migration-guide snippets parse for lint.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
zernonia added a commit that referenced this pull request Oct 5, 2026
…he scroll lock

Ports v2's shared, ref-counted owner (#2987) onto v3's layer stack: the stack's
private counter is gone, and `DismissableLayer` and `useBodyScrollLock` both
acquire and release through `shared/bodyPointerEvents`. A modal Dialog that is
open in the SSR render no longer leaves the body at `pointer-events: none`
after it closes (#2867).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Ray-lea added a commit to RayleaBot/RayleaBot that referenced this pull request Oct 9, 2026
从系统状态页点“添加机器人连接”跳到协议中心并打开新增弹窗,取消后整个页面不响应点击。弹窗与目标页面在同一次路由切换中挂载时,Reka 的滚动锁先在 nextTick 把 body 的 pointer-events 设为 none,DismissableLayer 随后才取得元素,把 none 记成原值;关闭时滚动锁因浮层集合未清空而跳过重置,DismissableLayer 又把记下的 none 写回 body。

Reka UI 2.11.0 改为由所有浮层共享一个计数的 body pointer-events 持有者(unovue/reka-ui#2987),不再各自记录原值。Web 与 Launcher 同步升级并更新工程基线与第三方声明;生产 E2E 补充从状态页打开弹窗、取消后页面仍可操作的回归用例。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zernonia added a commit that referenced this pull request Oct 27, 2026
… (#3070)

* feat(shared)!: port Base UI's overflow-based scroll lock

`useBodyScrollLock` is now a port of Base UI's `useScrollLock`
(mui/base-ui packages/utils/src/useScrollLock.ts):

- hides the overflow of the element that scrolls the page (`<html>` or
  `<body>`) and keeps the gutter with `scrollbar-gutter: stable`, or pins
  `<body>`'s size where that is unsupported; overlay scrollbars and iOS
  only hide the overflow
- one shared, reference-counted lock; lock and unlock are deferred by a
  macrotask so a same-tick hand-off never unlocks in between
- restores the original inline styles exactly, and waits for a lock that
  someone else still holds instead of snapshotting it
- only engages once the calling component has mounted (SSR safe)
- never touches `pointer-events`, `padding-right` or `--scrollbar-width`;
  no more `touchmove` interception on iOS

`ConfigProvider`'s `scrollBody` stays the escape hatch: `false` only
hides the overflow, `{ padding, margin }` offsets `<body>`.

BREAKING CHANGE: the scroll lock no longer sets `padding-right` /
`margin-right` on `<body>` or `--scrollbar-width` on `<html>`.

Refs #2822

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(DismissableLayer)!: internal backdrop instead of body pointer-events

A layer with `disableOutsidePointerEvents` no longer sets
`pointer-events: none` on `<body>`. Like Base UI's `InternalBackdrop`
(packages/react/src/utils/popups/InternalBackdrop.tsx), it mounts a
transparent, fixed `[data-reka-internal-backdrop]` right below itself
(before its popper wrapper or outermost fixed container). A press on it
is an ordinary outside press. Content stacked above it stays clickable,
see #1540. `shared/bodyPointerEvents.ts` is removed: nothing global is
written any more, so no style can get stuck on `<body>` after SSR
hydration, see #2987.

Following Base UI's Dialog / Popover / Menu / Select / Combobox:
- a modal Dialog / AlertDialog / Drawer closes only on a press on its
  own backdrop (internal one, overlay, or a container around it), and
  locks scroll whenever it is open, not only when an overlay renders;
  a Drawer with `modal="trap-focus"` no longer locks scroll
- the modal Popover / DropdownMenu trigger, the ContextMenu trigger
  area and the Combobox input are cut out of the backdrop; the
  `pointer-events: auto` overrides on them are gone
- layers below a modal layer stay inert, positioning wrapper included

`modal` defaults already match Base UI and are unchanged.

BREAKING CHANGE: `<body>` `pointer-events` is never set. Detect a modal
layer with `[data-reka-internal-backdrop]` instead. A modal Dialog no
longer closes on a press on an element stacked above its backdrop.

Refs #2822

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs: migration notes for the v3 scroll lock and modality

Adds "Modal layers no longer touch `<body>`" to the v3 migration guide
and section 14 to the agent guide: body `pointer-events` is never set,
the internal backdrop, own-backdrop dismissal for modal dialogs, the new
scroll lock (no padding, no `--scrollbar-width`, modal dialogs lock with
or without an overlay) and the unchanged `modal` defaults. Regenerates
the API meta for the updated prop descriptions.

Refs #2822

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(shared): remove the style attribute the scroll lock added on restore

When <html> or <body> had no style attribute before the lock, restoring
the snapshot left an empty style="" behind. Restore now removes the
attribute again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(DismissableLayer): stack the internal backdrop with the layer's z-index

- Copy the z-index of the layer (or of its positioning wrapper / fixed
  container) onto the backdrop, so page content with a lower z-index such
  as a sticky header is covered, while higher-z widgets stay clickable.
- A non-portaled layer inside a transform / filter / contain / will-change
  / backdrop-filter ancestor gets its backdrop in body, with a hole over
  the layer, instead of one only as large as that ancestor.
- Track the cutout with a ResizeObserver and window resize, and stop on
  unmount.
- Document the isolation: isolate app-root recommendation.
- Raise the Popover size budget by 1 KB (maintainer-approved).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs: renumber the Combobox section on the v3 agent migration page

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <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.

Two body pointer-events ownership edges left open by #2832 (DismissableLayer vs scroll lock)

2 participants