]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(devtools): use cleanupBuffer instead of modifying _buffer (#6812)
authorEduardo San Martin Morote <posva@users.noreply.github.com>
Mon, 3 Oct 2022 09:29:34 +0000 (11:29 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Oct 2022 09:29:34 +0000 (11:29 +0200)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
packages/runtime-core/src/devtools.ts

index 83d7483df39560faf1351e17bd55b2117085e83a..f05128d47aacee5acc6aefde12627760e9470fde 100644 (file)
@@ -28,7 +28,11 @@ interface DevtoolsHook {
   once: (event: string, handler: Function) => void
   off: (event: string, handler: Function) => void
   appRecords: AppRecord[]
-  _buffer: any[][]
+  /**
+   * Added at https://github.com/vuejs/devtools/commit/f2ad51eea789006ab66942e5a27c0f0986a257f9
+   * Returns wether the arg was buffered or not
+   */
+  cleanupBuffer?: (matchArg: unknown) => boolean
 }
 
 export let devtools: DevtoolsHook
@@ -109,18 +113,14 @@ const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
 export const devtoolsComponentRemoved = (
   component: ComponentInternalInstance
 ) => {
-  if (devtools && devtools._buffer.length) {
-    let wasBuffered = false
-    devtools._buffer = devtools._buffer.filter(item => {
-      if (item.some(arg => arg === component)) {
-        wasBuffered = true
-        return false
-      }
-      return true
-    })
-    if (wasBuffered) return
+  if (
+    devtools &&
+    typeof devtools.cleanupBuffer === 'function' &&
+    // remove the component if it wasn't buffered
+    !devtools.cleanupBuffer(component)
+  ) {
+    _devtoolsComponentRemoved(component)
   }
-  _devtoolsComponentRemoved(component)
 }
 
 function createDevtoolsComponentHook(hook: DevtoolsHooks) {