Skip to content

Commit bb443a0

Browse files
committed
fix: button wave memory leak
1 parent 3a79f72 commit bb443a0

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

components/_util/wave/WaveEffect.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ function showWaveEffect(node: HTMLElement, className: string) {
159159
node?.insertBefore(holder, node?.firstChild);
160160

161161
render(<WaveEffect target={node} className={className} />, holder);
162+
return () => {
163+
render(null, holder);
164+
if (holder.parentElement) {
165+
holder.parentElement.removeChild(holder);
166+
}
167+
};
162168
}
163169

164170
export default showWaveEffect;

components/_util/wave/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ export default defineComponent({
3333

3434
// =============================== Wave ===============================
3535
const showWave = useWave(
36-
instance,
3736
computed(() => classNames(prefixCls.value, hashId.value)),
3837
wave,
3938
);
4039
let onClick: (e: MouseEvent) => void;
4140
const clear = () => {
42-
const node = findDOMNode(instance);
41+
const node = findDOMNode(instance) as HTMLElement;
4342
node.removeEventListener('click', onClick, true);
4443
};
4544
onMounted(() => {

components/_util/wave/useWave.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import type { ComponentInternalInstance, ComputedRef, Ref } from 'vue';
1+
import type { ComputedRef, Ref } from 'vue';
2+
import { onBeforeUnmount, getCurrentInstance } from 'vue';
23
import { findDOMNode } from '../props-util';
34
import showWaveEffect from './WaveEffect';
45

56
export default function useWave(
6-
instance: ComponentInternalInstance | null,
77
className: Ref<string>,
88
wave?: ComputedRef<{ disabled?: boolean }>,
99
): VoidFunction {
10+
const instance = getCurrentInstance();
11+
let stopWave: () => void;
1012
function showWave() {
1113
const node = findDOMNode(instance);
12-
14+
stopWave?.();
1315
if (wave?.value?.disabled || !node) {
1416
return;
1517
}
16-
17-
showWaveEffect(node, className.value);
18+
stopWave = showWaveEffect(node, className.value);
1819
}
20+
onBeforeUnmount(() => {
21+
stopWave?.();
22+
});
1923

2024
return showWave;
2125
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy