🐛 Bug report
When stacked dialogs are used, closing the top dialog can make its content exit animation visually disappear. The Presence state and CSS animation events still run correctly, but the closing dialog's positioner loses its layer CSS variables during layerStack.remove(), causing its z-index to collapse while the node is still mounted for the exit animation.
💥 Steps to reproduce
- Using the official Zag.js nextjs examples -> Dialog examples -> Popover nested.
- Ensure the Dialog component is wrapped with Presence so that the close animation can play.
- Open D1 -> D2 -> D3
- Observe that D3/D2 content exit animation is not visible, or appears hidden behind the lower dialog/backdrop.
🧐 Expected behavior
The closing top dialog should keep its resolved stacking order until its exit animation completes. Its content and backdrop should remain visible while data-state="closed" animations are running.
🧭 Possible Solution
Freeze the resolved z-index before clearing layer style metadata in layerStack.remove().
layer.styleTargets?.forEach((getTarget) => {
const target = getTarget()
if (target) {
const { zIndex } = getComputedStyle(target)
if (zIndex && zIndex !== "auto") {
target.style.setProperty("z-index", zIndex)
}
clearLayerStyleMirror(target)
}
})
Then clear the frozen inline z-index when the layer is active again in syncLayers():
target.style.removeProperty("z-index")
applyLayerStackMetadata(layer, index, target)
🌍 System information
| Software |
Version(s) |
| Zag Version |
1.42.0 |
| Browser |
Chrome |
| Operating System |
Windows |
📝 Additional information
Please check the videos:
🐛 Bug report
When stacked dialogs are used, closing the top dialog can make its content exit animation visually disappear. The Presence state and CSS animation events still run correctly, but the closing dialog's
positionerloses its layer CSS variables duringlayerStack.remove(), causing its z-index to collapse while the node is still mounted for the exit animation.💥 Steps to reproduce
🧐 Expected behavior
The closing top dialog should keep its resolved stacking order until its exit animation completes. Its content and backdrop should remain visible while
data-state="closed"animations are running.🧭 Possible Solution
Freeze the resolved z-index before clearing layer style metadata in
layerStack.remove().Then clear the frozen inline z-index when the layer is active again in
syncLayers():🌍 System information
📝 Additional information
Please check the videos:
Issue:
https://github.com/user-attachments/assets/bb04b80e-a823-4d41-9d32-c688a4172aa2
solved:
https://github.com/user-attachments/assets/23431831-c761-4e5a-848c-6ee61badfaed