Skip to content

Commit b672137

Browse files
authored
perf: reduce the performance cost of component changed (#139)
1 parent 12bed15 commit b672137

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/devtools-kit/src/core/plugins/components.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { VueAppInstance } from '@vue/devtools-schema'
2+
import { debounce } from 'perfect-debounce'
23
import { setupDevToolsPlugin } from '../../api/plugin'
34
import { getAppRecord, getComponentId, getComponentInstance } from '../component/general'
45
import { devtoolsContext } from '../general/state'
@@ -84,6 +85,14 @@ export function registerComponentsDevTools(app: VueAppInstance) {
8485
}
8586
})
8687

88+
const debounceSendInspectorTree = debounce(() => {
89+
api.sendInspectorTree(INSPECTOR_ID)
90+
}, 120)
91+
92+
const debounceSendInspectorState = debounce(() => {
93+
api.sendInspectorState(INSPECTOR_ID)
94+
}, 120)
95+
8796
const componentAddedCleanup = hook.on.componentAdded(async (app, uid, parentUid, component) => {
8897
if (app?._instance?.type?.devtools?.hide)
8998
return
@@ -109,7 +118,7 @@ export function registerComponentsDevTools(app: VueAppInstance) {
109118
if (!appRecord)
110119
return
111120

112-
api.sendInspectorTree(INSPECTOR_ID)
121+
debounceSendInspectorTree()
113122
})
114123

115124
const componentUpdatedCleanup = hook.on.componentUpdated(async (app, uid, parentUid, component) => {
@@ -137,8 +146,8 @@ export function registerComponentsDevTools(app: VueAppInstance) {
137146
if (!appRecord)
138147
return
139148

140-
api.sendInspectorTree(INSPECTOR_ID)
141-
api.sendInspectorState(INSPECTOR_ID)
149+
debounceSendInspectorTree()
150+
debounceSendInspectorState()
142151
})
143152
const componentRemovedCleanup = hook.on.componentRemoved(async (app, uid, parentUid, component) => {
144153
if (app?._instance?.type?.devtools?.hide)
@@ -159,7 +168,7 @@ export function registerComponentsDevTools(app: VueAppInstance) {
159168
}) as string
160169
appRecord?.instanceMap.delete(id)
161170

162-
api.sendInspectorTree(INSPECTOR_ID)
171+
debounceSendInspectorTree()
163172
})
164173
devtoolsContext.componentPluginHookBuffer = [
165174
componentAddedCleanup,

0 commit comments

Comments
 (0)