Skip to content

Commit 588d91e

Browse files
committed
perf(kit): debounce sending of inspector tree/state updates
1 parent 0f8606b commit 588d91e

File tree

1 file changed

+12
-6
lines changed
  • packages/devtools-kit/src/ctx

1 file changed

+12
-6
lines changed

packages/devtools-kit/src/ctx/hook.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
TimelineLayerOptions,
1515
} from '../types'
1616
import { createHooks } from 'hookable'
17+
import { debounce } from 'perfect-debounce'
1718
import { getComponentBoundingRect } from '../core/component/state/bounding-rect'
1819
import { getInstanceName } from '../core/component/utils'
1920
import { highlight, unhighlight } from '../core/component-highlighter'
@@ -236,8 +237,7 @@ export function createDevToolsCtxHooks() {
236237
addInspector(inspector, plugin.descriptor)
237238
})
238239

239-
// send inspector tree
240-
hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_TREE, async ({ inspectorId, plugin }) => {
240+
const debounceSendInspectorTree = debounce(async ({ inspectorId, plugin }) => {
241241
if (!inspectorId || !plugin?.descriptor?.app)
242242
return
243243

@@ -251,6 +251,7 @@ export function createDevToolsCtxHooks() {
251251
filter: inspector?.treeFilter || '',
252252
rootNodes: [],
253253
}
254+
254255
await new Promise<void>((resolve) => {
255256
// @ts-expect-error hookable
256257
hooks.callHookWith(async (callbacks) => {
@@ -266,10 +267,12 @@ export function createDevToolsCtxHooks() {
266267
rootNodes: _payload.rootNodes,
267268
})))
268269
}, DevToolsMessagingHookKeys.SEND_INSPECTOR_TREE_TO_CLIENT)
269-
})
270+
}, 120)
270271

271-
// send inspector state
272-
hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, async ({ inspectorId, plugin }) => {
272+
// send inspector tree
273+
hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_TREE, debounceSendInspectorTree)
274+
275+
const debounceSendInspectorState = debounce(async ({ inspectorId, plugin }) => {
273276
if (!inspectorId || !plugin?.descriptor?.app)
274277
return
275278

@@ -305,7 +308,10 @@ export function createDevToolsCtxHooks() {
305308
state: _payload.state,
306309
})))
307310
}, DevToolsMessagingHookKeys.SEND_INSPECTOR_STATE_TO_CLIENT)
308-
})
311+
}, 120)
312+
313+
// send inspector state
314+
hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, debounceSendInspectorState)
309315

310316
// select inspector node
311317
hooks.hook(DevToolsContextHookKeys.CUSTOM_INSPECTOR_SELECT_NODE, ({ inspectorId, nodeId, plugin }) => {

0 commit comments

Comments
 (0)