From 6f7c62b09e2375cbe768437e1285b0daaab56d93 Mon Sep 17 00:00:00 2001 From: Hwacc Date: Fri, 10 Jul 2026 17:50:04 +0800 Subject: [PATCH 1/3] Preserve target z-index when updating layer stack --- packages/utilities/dismissable/src/layer-stack.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/utilities/dismissable/src/layer-stack.ts b/packages/utilities/dismissable/src/layer-stack.ts index 1a80a514a1..564bb51ad3 100644 --- a/packages/utilities/dismissable/src/layer-stack.ts +++ b/packages/utilities/dismissable/src/layer-stack.ts @@ -109,6 +109,10 @@ export const layerStack = { 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) } }) @@ -142,6 +146,7 @@ export const layerStack = { layer.styleTargets?.forEach((getTarget) => { const target = getTarget() if (!target || target === layer.node) return + target.style.removeProperty("z-index") applyLayerStackMetadata(layer, index, target) const { zIndex } = getComputedStyle(layer.node) target.style.setProperty("--z-index", zIndex) From df48d395c1c74a37037d6c13019271ceb7a2c4fc Mon Sep 17 00:00:00 2001 From: Hwacc Date: Tue, 14 Jul 2026 16:22:06 +0800 Subject: [PATCH 2/3] Preserve inline z-index when syncing layers Store each style target's prior z-index before freezing it, then restore that exact value on cleanup instead of always removing the inline property. This prevents clobbering consumer-defined z-index styles. --- .../utilities/dismissable/src/layer-stack.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/utilities/dismissable/src/layer-stack.ts b/packages/utilities/dismissable/src/layer-stack.ts index 564bb51ad3..d415ae384a 100644 --- a/packages/utilities/dismissable/src/layer-stack.ts +++ b/packages/utilities/dismissable/src/layer-stack.ts @@ -24,6 +24,12 @@ export interface Layer { const LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss" +/** + * we use a WeakMap to record the target's PRIOR inline z-index (may be an empty string) so that + * syncLayers() can precisely restore it and never stomps consumer-provided inline z-index. + */ +const frozenZMap = new WeakMap() + export const layerStack = { layers: [] as Layer[], branches: [] as HTMLElement[], @@ -111,6 +117,7 @@ export const layerStack = { if (target) { const { zIndex } = getComputedStyle(target) if (zIndex && zIndex !== "auto") { + frozenZMap.set(target, zIndex) target.style.setProperty("z-index", zIndex) } clearLayerStyleMirror(target) @@ -146,7 +153,15 @@ export const layerStack = { layer.styleTargets?.forEach((getTarget) => { const target = getTarget() if (!target || target === layer.node) return - target.style.removeProperty("z-index") + if (frozenZMap.has(target)) { + const prior = frozenZMap.get(target) + if (prior) { + target.style.setProperty("z-index", prior) + } else { + target.style.removeProperty("z-index") + } + frozenZMap.delete(target) + } applyLayerStackMetadata(layer, index, target) const { zIndex } = getComputedStyle(layer.node) target.style.setProperty("--z-index", zIndex) From e5bf8a293e6c7ae5180d5e8bd1eac924ae0a9fca Mon Sep 17 00:00:00 2001 From: Hwacc Date: Wed, 15 Jul 2026 13:43:37 +0800 Subject: [PATCH 3/3] Refactor layer stack z-index cleanup logic --- .../utilities/dismissable/src/layer-stack.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/utilities/dismissable/src/layer-stack.ts b/packages/utilities/dismissable/src/layer-stack.ts index d415ae384a..564bb51ad3 100644 --- a/packages/utilities/dismissable/src/layer-stack.ts +++ b/packages/utilities/dismissable/src/layer-stack.ts @@ -24,12 +24,6 @@ export interface Layer { const LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss" -/** - * we use a WeakMap to record the target's PRIOR inline z-index (may be an empty string) so that - * syncLayers() can precisely restore it and never stomps consumer-provided inline z-index. - */ -const frozenZMap = new WeakMap() - export const layerStack = { layers: [] as Layer[], branches: [] as HTMLElement[], @@ -117,7 +111,6 @@ export const layerStack = { if (target) { const { zIndex } = getComputedStyle(target) if (zIndex && zIndex !== "auto") { - frozenZMap.set(target, zIndex) target.style.setProperty("z-index", zIndex) } clearLayerStyleMirror(target) @@ -153,15 +146,7 @@ export const layerStack = { layer.styleTargets?.forEach((getTarget) => { const target = getTarget() if (!target || target === layer.node) return - if (frozenZMap.has(target)) { - const prior = frozenZMap.get(target) - if (prior) { - target.style.setProperty("z-index", prior) - } else { - target.style.removeProperty("z-index") - } - frozenZMap.delete(target) - } + target.style.removeProperty("z-index") applyLayerStackMetadata(layer, index, target) const { zIndex } = getComputedStyle(layer.node) target.style.setProperty("--z-index", zIndex)