Programmatically opened dialog is dismissed when an unrelated popover closes

Open
#3,695 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@akzarma is already working on this.

Since Nov 26, 2026.

  • #3699 by @akzarma — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Domain
frontend

Research direction

The layer ordering comes from getParentNode() in packages/utilities/dismissable/src/layer-stack.ts, which falls back to the top layer when a layer has no registered trigger. Start by reading that fallback and how #3599 changed it, then reproduce with the single-file HTML in the issue. Done means a programmatically opened dialog stays open when an unrelated popover closes, while dialogs opened from inside another layer still follow their parent.

Written by the indexing model from the issue text.

Description

🐛 Bug report

Closing an unrelated popover also dismisses a dialog opened with dialogApi.setOpen(true). The dialog and popover are DOM siblings, and the dialog has no registered Zag trigger. This reproduces on Zag 1.49.0 with the vanilla adapter.

💥 Steps to reproduce

  1. Click Open popover.
  2. Click Open dialog and confirm both layers are open.
  3. Click Close popover only inside the dialog. It calls only popoverApi.setOpen(false).
  4. Both layers close. The page logs Dialog received a dismiss request from: popover from onRequestDismiss.

💻 Link to reproduction

Import the single-file reproduction into CodeSandbox

To run it locally, save the following as index.html, start python3 -m http.server 8000 in the same directory, and open http://localhost:8000.

<!doctype html>
<meta charset="utf-8">
<title>Zag independent layer dismissal</title>
<button id="open-popover">Open popover</button>
<button id="open-dialog">Open dialog</button>
<div id="positioner"><div id="popover">Independent popover</div></div>
<div id="dialog" style="position:fixed;top:8rem;left:18rem;padding:1rem;border:1px solid">
  <button id="close-popover">Close popover only</button>
</div>
<pre id="log"></pre>

<script type="module">
  import * as dialog from "https://cdn.jsdelivr.net/npm/@zag-js/[email protected]/+esm"
  import * as popover from "https://cdn.jsdelivr.net/npm/@zag-js/[email protected]/+esm"
  import { VanillaMachine, normalizeProps, spreadProps } from "https://cdn.jsdelivr.net/npm/@zag-js/[email protected]/+esm"

  const byId = (id) => document.getElementById(id)
  const openPopover = byId("open-popover")
  const positioner = byId("positioner")
  const popoverContent = byId("popover")
  const dialogContent = byId("dialog")

  function mount(component, options, render) {
    const machine = new VanillaMachine(component.machine, options)
    const api = () => component.connect(machine.service, normalizeProps)
    const sync = () => render(api())
    machine.subscribe(sync)
    machine.start()
    sync()
    return api
  }

  const popoverApi = mount(popover, {
    id: "popover",
    closeOnInteractOutside: false,
    positioning: { placement: "bottom-start" },
  }, (api) => {
    spreadProps(openPopover, api.getTriggerProps())
    spreadProps(positioner, api.getPositionerProps())
    spreadProps(popoverContent, api.getContentProps())
  })

  const dialogApi = mount(dialog, {
    id: "dialog",
    "aria-label": "Independent dialog",
    closeOnInteractOutside: false,
    closeOnEscape: false,
    onRequestDismiss(event) {
      const source = event.detail.targetLayer?.getAttribute("data-scope")
      byId("log").textContent = `Dialog received a dismiss request from: ${source}`
    },
  }, (api) => spreadProps(dialogContent, api.getContentProps()))

  byId("open-dialog").onclick = () => dialogApi().setOpen(true)
  byId("close-popover").onclick = () => popoverApi().setOpen(false)
</script>

🧐 Expected behavior

Only the popover closes. The independent dialog remains open.

🧭 Possible solution

This appears to be a remaining case after #3599. In a separate check on 1.49.0, an external Zag trigger keeps the dialog open when the popover closes. Without a trigger, getParentNode() falls back to the top layer. Could a programmatically opened dialog explicitly opt out of that fallback? Dialogs opened from inside another layer could continue to follow their parent.

🌍 System information

Software Version(s)
Zag 1.49.0 with @zag-js/vanilla. Also reproduced on 1.47.0 with the equivalent vanilla setup.
Browser Chrome 146.0.7680.165
Operating system macOS 26.4, Apple Silicon
Dominant language
TypeScript
Stars
5.3k
Forks
320
Avg merge
1d 22h
Merged PRs (30d)
60

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from chakra-ui/zag

All issues in chakra-ui/zag

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.