Explorar el Código

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

fix #4829
Che Guevara hace 4 años
padre
commit
6b32f0d976
Se han modificado 1 ficheros con 7 adiciones y 2 borrados
  1. 7 2
      packages/runtime-core/src/devtools.ts

+ 7 - 2
packages/runtime-core/src/devtools.ts

@@ -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)
   }
 }