Programmatically opened dialog is dismissed when an unrelated popover closes
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, typescript
- 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
- Click Open popover.
- Click Open dialog and confirm both layers are open.
- Click Close popover only inside the dialog. It calls only
popoverApi.setOpen(false). - Both layers close. The page logs
Dialog received a dismiss request from: popoverfromonRequestDismiss.
💻 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from chakra-ui/zag
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
date-input: zoned values show in the timeZone prop (UTC) instead of their own zonePossibly taken @Yahiro025 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
dismissable: LayerDismissEvent isn't exportedPossibly taken @abu-tahir-0 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Slider: marker data-state ignores origin "center" / "end"Possibly taken @itisrmk claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
area:vscode bug has repro platform:macos platform:vscode regression
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
anthropics/claude-code#113502 ·
-
Add: Rajdhani TV HDOpencheck:passed streams:add
Difficulty 1/5 Under an hour Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
effort/l priority/p1 risk/high triage/core
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
iflytek/skillhub#1188 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Fission-AI/OpenSpec#2337 ·
Maintainers usually reply within 1 day