From ca7ba6416e7b768da79ec17307a63f05d00d4d23 Mon Sep 17 00:00:00 2001 From: amanmaurya92 Date: Wed, 5 Aug 2026 00:40:29 +0530 Subject: [PATCH] fix(overlays): ensure overlayIndex is greater than any existing overlay in DOM --- core/src/utils/overlays.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index ddcce8f4c1c..d5d26987cad 100644 --- a/core/src/utils/overlays.ts +++ b/core/src/utils/overlays.ts @@ -97,7 +97,24 @@ export const prepareOverlay = (el: T) => { */ connectListeners(document); } - const overlayIndex = lastOverlayIndex++; + let maxIndex = 0; + + if (typeof document !== 'undefined') { + const overlays = Array.from( + document.querySelectorAll( + 'ion-alert,ion-action-sheet,ion-loading,ion-modal,ion-picker-legacy,ion-popover,ion-toast' + ) + ) as HTMLIonOverlayElement[]; + + for (const o of overlays) { + if (o !== el && o.overlayIndex !== undefined) { + maxIndex = Math.max(maxIndex, o.overlayIndex); + } + } + } + + const overlayIndex = Math.max(lastOverlayIndex, maxIndex + 1); + lastOverlayIndex = overlayIndex + 1; /** * overlayIndex is used in the overlay components to set a zIndex. * This ensures that the most recently presented overlay will be