Modals stay modal (page inert, scrim live) for the whole exit animation: the first click after an outside dismissal is lost

Đang mở
#1,334 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript

Hướng nghiên cứu

Start with components/Dialog/Dialog.svelte, primitives/presence.svelte.js, and primitives/layer.js to trace how closing state, animation completion, modal behavior, focus, and scroll locking interact. Reproduce the lost click using the provided Playwright timing steps, then inspect the ModalContract browser test mentioned in the issue. Done means a click shortly after dismissal reaches the page button and a nonterminating descendant animation cannot keep the dialog modal; the issue does not name exact test paths.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:components bug

What happens

A modal (Dialog, AlertDialog, Drawer, Sheet, CommandPalette) is closed by pressing outside it (or Escape, or a button). The user then clicks a button on the page behind it right away: the click does nothing, a second click is needed. The cursor looks stuck.

Measured on WebKit (Playwright 1.65 WebKit, headless, real mouse events; @codeatlasdev/ui 4.6.0), a click on a page button N ms after the dismissal:

ms after dismissal button handler runs
30, 80 no (press lost)
150, 250, 400 yes

The same on Chromium (30 ms: lost). It is the whole 150 ms exit animation (--ca-enter-fast).

Root cause (installed 4.6.0, dist/)

Closing only flips data-state="closed"; the layer stays alive, still modal, until the exit animation finishes:

  • components/Dialog/Dialog.svelte:109,118 createPresence(() => open) / {#if presence.present}: the <dialog> stays rendered while exiting.
  • primitives/presence.svelte.js:16-46 (exiting = true, rAF, then Promise.allSettled(anims.map(a => a.finished)) at line 40): exiting only clears when every running animation, in the whole subtree, has finished.
  • primitives/layer.js:435-436 dialog.showModal() and :460-466 dialog.close() run only in the layer's close(), which the owner calls when the {#if} branch is destroyed, i.e. after the exit. Until then the dialog is a modal: the rest of the page is inert (HTML "blocked by a modal dialog") and ::backdrop (dialog.css:51) still takes the pointer. A press on the page goes to the closing dialog: layer.js:451-456 onClick calls onDismiss again (a no-op) and the click never reaches the button.
  • layer.js:25-35: a closing entry is skipped by topInteractive/topModal, so the kit already treats the layer as "closing"; only the platform state (modal, inert, focus trap layer.js:434, scroll lock :432) is not released.

Side effect of the same line: an animation that never ends inside the dialog (a spinner with animation-iteration-count: infinite) makes Promise.allSettled wait forever, so the dialog never leaves (and stays modal).

Minimal reproduction

<script>
  import { Dialog, Button } from "@codeatlasdev/ui";
  let open = $state(false), n = $state(0);
</script>
<Button onclick={() => (open = true)}>Open</Button>
<Button id="other" onclick={() => n++}>Other {n}</Button>
<Dialog bind:open title="Dialog">hello</Dialog>

Open the dialog, press the scrim, and press #other within 150 ms (Playwright: page.mouse.click(scrim), page.waitForTimeout(30), page.mouse.click(other)): n stays 0.

Expected

A layer that has started closing must not intercept input: the page answers the first click after a dismissal, at any time.

Proposed fix

When a modal layer starts closing (closing() turns true in modalLayer), release the platform side at once and keep only the visual exit: release the focus trap and the scroll lock, dialog.close() then dialog.show() (non-modal, no ::backdrop, no inert page; re-focus the previously focused element after show() because it moves focus into the dialog) and draw the scrim fade with the dialog's own box-shadow spread, or fade a non-interactive sibling. pointer-events: none on [data-state="closed"] for the panel. Independently: in presence.svelte.js ignore animations whose effect.getComputedTiming().endTime is Infinity.

Also add a browser test (ModalContract-style): dismiss by scrim, click a page button 0/30/80 ms later, expect one handler call each.

Workaround in Atlas

codeatlasdev/atlas#501: one document-level observer finishes the exit animation of any closing dialog.ca-overlay (the kit then drops the layer the next frame), plus .ca-floating[data-state="closed"] { pointer-events: none }. Documented with the removal condition in docs/desktop.md ("UI kit workarounds"). Atlas will delete it when a kit release passes its regression test without it.

Ngôn ngữ chính
TypeScript
Star
6
Fork
3
Merge trung bình
5 giờ 21 phút
Pull request đã merge (30 ngày)
378

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codeatlasdev/ui

Tất cả issue của codeatlasdev/ui

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.