Skip to content

[Bug]: DismissableLayer modal: body pointer-events blocking is lost when one modal layer opens while another (animated) modal layer is closing #2784

Closed

Description

@kolirt

Environment

Development/Production OS: macOS 15.3.1 (24D70, arm64)
Node version: 22.21.1
Package manager: yarn@1.22.22
Reka UI version: 2.9.6
Vue version: 3.5.32
CSS framework: tailwindcss@4.2.2
Client OS: macOS 15.3.1
Browser: Chrome 149.0.0.0

Link to minimal reproduction

https://kolirt.github.io/reka-ui-dismissable-layer-body-pointer-events-repro/

Steps to reproduce

Live demo: https://kolirt.github.io/reka-ui-dismissable-layer-body-pointer-events-repro/
Source: https://github.com/kolirt/reka-ui-dismissable-layer-body-pointer-events-repro

Manual:

  1. Click Open popover (a modal Popover whose content has a CSS exit animation; its PopoverRoot stays mounted — only open flips to false on close).
  2. Click Pick → close popover + open dialog — it closes the popover and opens a modal Dialog in the same tick.
  3. Wait ~half a second (until the popover's exit animation finishes) and click the amber button in the top bar.

The button behind the open modal dialog receives the click. The status panel shows document.body.style.pointerEvents live: it is none right after the handoff, then flips back to '' the moment the popover's exit animation ends — while the dialog is still open.

Automated: click Auto-run ×20 — the leak counter reaches 20/20 (fully deterministic).

Required ingredients (all three, see README):

  • the closing popover's PopoverRoot stays mounted (only open flips) and its content has a CSS exit animation, so its DismissableLayer teardown is delayed;
  • a modal Dialog mounts in the same tick the popover starts closing;
  • both layers are modal (disableOutsidePointerEvents).

If the popover has no exit animation (or its whole root is unmounted via v-if), the teardown is synchronous and the bug does not occur.

Describe the bug

DismissableLayer coordinates modal outside-pointer blocking through a single module-level context: one shared originalBodyPointerEvents string plus the layersWithOutsidePointerEventsDisabled set, applied to document.body.style.pointerEvents.

When a modal layer B (Dialog) mounts while another modal layer A (Popover with a CSS exit animation) is still animating out, the body lock is silently lost at the end of A's animation:

  1. A opens — set {A}, originalBodyPointerEvents = '' saved, body → none.
  2. B mounts while A is animating out — set size ≠ 0, so B only adds itself: set {A, B}. Body stays none. Correct so far.
  3. A unmounts when its exit animation ends — A's watchEffect cleanup sees size === 2, skips the restore; A is deleted from the set → set {B}.
  4. The set-size change re-triggers B's own watchEffect (the effect reads layersWithOutsidePointerEventsDisabled.size). Its cleanup runs first and now sees size === 1 && originalBodyPointerEvents != null → restores body to ''. The effect then re-runs, sees size !== 0, and never re-applies none.

Result: the modal dialog is still open, but document.body.style.pointerEvents is back to '' — everything behind the modal is clickable again.

Expected behavior

While at least one layer with disableOutsidePointerEvents is open, document.body.style.pointerEvents stays none. The original value is restored only when the last such layer unmounts. A modal layer that closes must never drop the body lock that another still-open modal layer relies on.

Context & Screenshots (if applicable)

No response

Activity

  1. added
    bug
    on Jul 10, 2026
  2. 61021 commented on Jul 31, 2026

    @61021
    Contributor

    Confirmed, and it's still live on current releases: your repro leaks 20/20 on 2.10.1 and on v2 HEAD, and 0/20 with the fix in #2832.

    One update to the mechanism for the record: the watchEffect re-trigger path you traced matches ≤2.9.9 and was fixed by #2678 in 2.9.10. What keeps the symptom alive since then is a second writer — useBodyScrollLock's resetBodyStyle() clears body.style.pointerEvents unconditionally when the last scroll-lock holder releases. In this composition that holder is the closing popover itself (PopoverContentModal keeps its lock until the exit animation ends), while the dialog holds no scroll lock at all (that lives on DialogOverlay, which is optional and not rendered here) — so the popover's teardown wipes the body lock the dialog's DismissableLayer still owns. Full trace in #2832.

    Great repro, by the way — the deterministic auto-run made bisecting this across releases trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions