Repository navigation
fix(DismissableLayer): share one ref-counted owner for body pointer-events - #2987
Conversation
…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
|
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
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughA shared per-document lock now coordinates body ChangesBody pointer-events ownership
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The shared lock restores body pointer-events after owners release. No change introduced here has been shown to block merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to 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 Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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: |
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>
…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>
从系统状态页点“添加机器人连接”跳到协议中心并打开新增弹窗,取消后整个页面不响应点击。弹窗与目标页面在同一次路由切换中挂载时,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>
… (#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>
Fixes #2867
What happens
useBodyScrollLockandDismissableLayerboth writedocument.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 onv2:DismissableLayersaves whatever the body has at that moment asoriginalBodyPointerEvents. That's the lock's'none', and the layer writes it back on its final restore. Once both have closed, the body is stuck atpointer-events: noneuntil a reload.'none'while the lock is still meant to hold it.A deterministic real-world trigger for edge 1 is a modal
Dialogthat's open in the SSR render (details in #2867 (comment)). Hydration runs outside a scheduler flush, soDialogOverlayImpl's scroll-locknextTicksets'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 aWeakMap<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:
useBodyScrollLockacquires where it used to set'none', keeping the samenextTicktiming. It releases inresetBodyStyle()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 inresetBodyStyle()is no longer needed, so it's removed, andshared/no longer importsDismissableLayer/context.DismissableLayeracquires with its element as the owner when adisableOutsidePointerEventslayer registers, and releases in the sameonCleanup. This replacescontext.originalBodyPointerEvents. The layer registry, the stack order, and the per-layerpointer-events: auto/nonestyling are unchanged.Since the owner doesn't care who comes or goes first, both edges close. A page's own inline
pointer-eventsvalue 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 sharedoriginalBodyPointerEventsmixed documents. No public exports change.Tests
'none'until the lock releases. Red before.pointer-events: autois preserved through a lock + layer cycle and a lock-only cycle. Red before.Dialog.ssr.test.tsserver-renders an open modalDialog(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.test:coverage).pnpm --filter reka-ui build(vue-tsc+ tsdown),eslint ., andsizeall pass.Notes
pointer-events: none, overflow-based lock, non-modal defaults #2822 plans to stop setting bodypointer-eventsin v3, which removes the conflict there. This is the smallest change that gives the property a single owner without moving the scroll lock or layer stack around.nextTickis kept only so its timing stays the same. Its old comment ("let dismissibleLayer set previous pointerEvent first") no longer applies, since the order doesn't matter anymore.Summary by CodeRabbit
Bug Fixes
Tests