Skip to content

Commit b2f2dbf

Browse files
gjfeitolking
andauthored
fix(components): [focus-trap, popper, tooltip] memory leak (element-plus#20147)
* fix(components): [focus-trap, popper, tooltip] memory leak * fix(components): [popper] memory leak * fix(components): [popper] memory leak * fix(components): [focus-trap, popper, tooltip] memory leak --------- Co-authored-by: qiang <qw13131wang@gmail.com>
1 parent b92ca7f commit b2f2dbf

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

packages/components/focus-trap/src/focus-trap.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ export default defineComponent({
330330
forwardRef.value.removeEventListener('focusout', onFocusOut)
331331
forwardRef.value = undefined
332332
}
333+
334+
lastFocusBeforeTrapped = null
335+
lastFocusAfterTrapped = null
333336
})
334337
335338
return {

packages/components/popper/src/composables/use-content.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { computed, inject, onMounted, ref, unref, watch } from 'vue'
1+
import {
2+
computed,
3+
inject,
4+
onBeforeUnmount,
5+
onMounted,
6+
ref,
7+
unref,
8+
watch,
9+
} from 'vue'
210
import { isUndefined } from 'lodash-unified'
311
import { usePopper } from '@element-plus/hooks'
412
import { POPPER_INJECTION_KEY } from '../constants'
@@ -74,6 +82,10 @@ export const usePopperContent = (props: PopperContentProps) => {
7482
)
7583
})
7684

85+
onBeforeUnmount(() => {
86+
popperInstanceRef.value = undefined
87+
})
88+
7789
return {
7890
attributes,
7991
arrowRef,

packages/components/popper/src/composables/use-focus-trap.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref } from 'vue'
1+
import { onBeforeUnmount, ref } from 'vue'
22

33
import type { SetupContext } from 'vue'
44
import type { PopperContentEmits, PopperContentProps } from '../content'
@@ -44,6 +44,10 @@ export const usePopperContentFocusTrap = (
4444
emit('close')
4545
}
4646

47+
onBeforeUnmount(() => {
48+
focusStartRef.value = undefined
49+
})
50+
4751
return {
4852
focusStartRef,
4953
trapped,

packages/components/popper/src/content.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ onMounted(() => {
146146
onBeforeUnmount(() => {
147147
triggerTargetAriaStopWatch?.()
148148
triggerTargetAriaStopWatch = undefined
149+
contentRef.value = undefined
149150
})
150151
151152
defineExpose({

packages/components/tooltip/src/tooltip.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<script lang="ts" setup>
5454
import {
5555
computed,
56+
onBeforeUnmount,
5657
onDeactivated,
5758
provide,
5859
readonly,
@@ -165,6 +166,10 @@ const isFocusInsideContent = (event?: FocusEvent) => {
165166
166167
onDeactivated(() => open.value && hide())
167168
169+
onBeforeUnmount(() => {
170+
toggleReason.value = undefined
171+
})
172+
168173
defineExpose({
169174
/**
170175
* @description el-popper component instance

0 commit comments

Comments
 (0)