From ca2174cff0b460fb8228b403c0068f9f855015c4 Mon Sep 17 00:00:00 2001 From: Kael Date: Sat, 2 Dec 2023 20:43:24 +1100 Subject: [PATCH] perf(VOverlay): only add resize listener when overlay is open closes #18372 --- .../src/components/VOverlay/locationStrategies.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/vuetify/src/components/VOverlay/locationStrategies.ts b/packages/vuetify/src/components/VOverlay/locationStrategies.ts index 222d5e4de76..8700a417deb 100644 --- a/packages/vuetify/src/components/VOverlay/locationStrategies.ts +++ b/packages/vuetify/src/components/VOverlay/locationStrategies.ts @@ -83,22 +83,18 @@ export function useLocationStrategies ( useToggleScope(() => !!(data.isActive.value && props.locationStrategy), reset => { watch(() => props.locationStrategy, reset) onScopeDispose(() => { + window.removeEventListener('resize', onResize) updateLocation.value = undefined }) + window.addEventListener('resize', onResize, { passive: true }) + if (typeof props.locationStrategy === 'function') { updateLocation.value = props.locationStrategy(data, props, contentStyles)?.updateLocation } else { updateLocation.value = locationStrategies[props.locationStrategy](data, props, contentStyles)?.updateLocation } }) - - window.addEventListener('resize', onResize, { passive: true }) - - onScopeDispose(() => { - window.removeEventListener('resize', onResize) - updateLocation.value = undefined - }) } function onResize (e: Event) {