fix(devtools): fix memory leak when devtools is not installed (#4833)

fix #4829
This commit is contained in:
Che Guevara 2021-11-02 11:26:40 +08:00 committed by GitHub
parent b5c0142cf0
commit 6b32f0d976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,12 @@ export let devtools: DevtoolsHook
let buffer: { event: string; args: any[] }[] = []
let devtoolsNotInstalled = false
function emit(event: string, ...args: any[]) {
if (devtools) {
devtools.emit(event, ...args)
} else {
} else if (!devtoolsNotInstalled) {
buffer.push({ event, args })
}
}
@ -56,7 +58,10 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
// clear buffer after 3s - the user probably doesn't have devtools installed
// at all, and keeping the buffer will cause memory leaks (#4738)
setTimeout(() => {
buffer = []
if (!devtools) {
devtoolsNotInstalled = true
buffer = []
}
}, 3000)
}
}