Repository navigation
fix(DismissableLayer): keep body pointer-events locked when the last scroll lock releases - #2832
Conversation
…scroll lock releases useBodyScrollLock's resetBodyStyle cleared document.body.style.pointerEvents unconditionally once the last scroll-lock holder released. When that holder was a closing modal Popover whose content unmounts after its exit animation, and a modal layer without its own scroll lock (e.g. a Dialog rendered without an Overlay) was already open, the body lock owned by DismissableLayer was wiped and everything behind the open modal became clickable (unovue#2784). Only clear body pointer-events when no DismissableLayer currently disables outside pointer events. The layer registry moves to a plain module (DismissableLayer/context.ts) so useBodyScrollLock can consult it without importing the component and creating a cycle through the shared barrel. Fixes unovue#2784 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis change centralizes ChangesDismissable layer lock coordination
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant Popover
participant Dialog
participant DismissableLayerContext
participant BodyScrollLock
participant DocumentBody
Popover->>DismissableLayerContext: Register modal layer
DocumentBody->>DocumentBody: Set pointerEvents to none
Dialog->>DismissableLayerContext: Register while Popover closes
Popover->>DismissableLayerContext: Remove closing layer
DismissableLayerContext->>BodyScrollLock: Report active Dialog layer
BodyScrollLock->>DocumentBody: Preserve pointerEvents none
Dialog->>DismissableLayerContext: Remove final modal layer
BodyScrollLock->>DocumentBody: Restore original pointerEvents
🚥 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: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/DismissableLayer/DismissableLayer.test.ts`:
- Around line 137-141: Update the beforeEach for “sibling layers with
disableOutsidePointerEvents” to clear both module-level registries,
context.layersRoot and context.layersWithOutsidePointerEventsDisabled, before
each test. Keep the existing document body and pointer-events resets unchanged,
matching the cleanup used in the “scroll-lock handoff” describe block.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cf37d833-9c1f-438d-8761-2d67c29cd371
📒 Files selected for processing (5)
packages/core/src/DismissableLayer/DismissableLayer.test.tspackages/core/src/DismissableLayer/DismissableLayer.vuepackages/core/src/DismissableLayer/DismissableLayerBranch.vuepackages/core/src/DismissableLayer/context.tspackages/core/src/shared/useBodyScrollLock.ts
…reEach Matches the scroll-lock handoff suite so the suite stays order-independent even if a failing test skips its unmounts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…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>
Fixes #2784
What happens
useBodyScrollLockandDismissableLayerboth writedocument.body.style.pointerEventswithout consulting each other, and the scroll lock'sresetBodyStyle()— which runs when the last scroll-lock holder releases — cleared it unconditionally.In the repro, the last scroll-lock holder is the closing popover itself:
PopoverContentModalholdsuseBodyScrollLock(true)until its content unmounts, i.e. until the exit animation finishes. The dialog that opened mid-animation disables outside pointer events through itsDismissableLayer, but holds no scroll lock of its own — a dialog's lock lives onDialogOverlayImpl, and the repro (legitimately) renders no overlay. So when the popover's exit animation ends, its scroll lock is the last one out and wipes the body lock the dialog still depends on.Instrumented trace of one handoff on
v2HEAD (temporary logs in both writers):DismissableLayer's own bookkeeping is correct throughout — the dialog's layer is registered, and the departing layer doesn't restore because it isn't the last one. Nothing re-applies the style afterwards because no layer-registry state changes again.Relationship to the issue's analysis
The
watchEffectre-trigger mechanism described in #2784 matches the pre-2.9.10DismissableLayerand was fixed by #2678 (the repro pins2.9.6, which predates it). The leak itself is not stale, though — running the repro's own Auto-run ×20 (headless Chromium, its "exit animation played" self-check green):v2HEADv2HEAD + this PRThe exit animation isn't essential either: the same stomp happens with no animation at all when a modal popover opens and closes over an overlay-less modal dialog (covered by the second regression test).
The fix
resetBodyStyle()now leavespointerEventsalone while anyDismissableLayerstill hasdisableOutsidePointerEventsactive; that layer's cleanup restores it once the last disabling layer is gone. The scroll lock's other resets (overflow, padding/margin,--scrollbar-width) are unchanged.To let
useBodyScrollLock(inshared/) read the layer registry without importing the component —DismissableLayer.vueimports from thesharedbarrel, so that would be a cycle — the module-levelcontextmoves verbatim toDismissableLayer/context.ts. The.vuere-exports it, so the existing import surface is unchanged (contextisn't in the package's public exports; the only other consumer,DismissableLayerBranch.vue, is updated).Tests
vue-tscand lint clean.Out of scope (happy to follow up)
The underlying shape — two owners writing one property — has two more edges this PR deliberately doesn't touch:
DismissableLayercan capture the scroll lock's'none'asoriginalBodyPointerEvents(when a layer mounts while abodyLockis already active) and write it back on final restore, leaving the body atpointer-events: nonewith nothing open. Pre-existing, reachable both before and after this PR.DismissableLayer's restore doesn't consult still-active scroll locks.A shared, refcounted owner for body
pointer-events(first acquirer saves the original, last release restores it) would close the whole class, and seems to line up with where #2822 wants v3 to go. Glad to do that as a follow-up if you'd take it — kept this one minimal since the guarded path is the one #2784 actually hits.Summary by CodeRabbit