Skip to content

Commit 611af04

Browse files
authored
feat(kit): high-performance mode (#280)
1 parent 35918fe commit 611af04

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

packages/core/src/bridge-events/devtools-actions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { InspectorStateEditorPayload } from '@vue/devtools-kit'
2-
import { stringify } from '@vue/devtools-kit'
2+
import { toggleHighPerfMode as _toggleHighPerfMode, stringify } from '@vue/devtools-kit'
33
import { defineDevToolsAction } from '../bridge'
44

55
export const checkVueInspectorDetected = defineDevToolsAction<boolean>('devtools:check-vue-inspector-detected', async (devtools) => {
@@ -54,7 +54,7 @@ export const updateInspectorTreeId = defineDevToolsAction('devtools:update-inspe
5454
devtools.context.activeInspectorTreeId = payload
5555
})
5656

57-
export const unhighlightElement = defineDevToolsAction('devtools:unhighlight-element', (devtools, payload) => {
57+
export const unhighlightElement = defineDevToolsAction('devtools:unhighlight-element', (devtools) => {
5858
return devtools.api.unhighlightElement()
5959
})
6060

@@ -98,3 +98,7 @@ export const getDevToolsState = defineDevToolsAction('devtools:get-state', (devt
9898
activeAppRecordId: devtools.state.activeAppRecordId,
9999
}
100100
})
101+
102+
export const toggleHighPerfMode = defineDevToolsAction('devtools:toggle-high-perf-mode', (_, payload) => {
103+
_toggleHighPerfMode(payload)
104+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { devtoolsState } from '../../state'
2+
3+
export function toggleHighPerfMode(state?: boolean) {
4+
devtoolsState.highPerfModeEnabled = state ?? !devtoolsState.highPerfModeEnabled
5+
}

packages/devtools-kit/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { setupDevToolsPlugin } from './api'
55
import { addCustomTab } from './core/custom-tab'
66
import { addCustomCommand, removeCustomCommand } from './core/custom-command'
77
import { toggleComponentInspectorEnabled } from './core/component-inspector'
8+
import { toggleHighPerfMode } from './core/high-perf-mode'
89

910
export type * from './core/custom-tab'
1011
export type * from './core/custom-command'
@@ -48,4 +49,5 @@ export {
4849
setupDevToolsPlugin,
4950
setDevToolsEnv,
5051
toggleComponentInspectorEnabled,
52+
toggleHighPerfMode,
5153
}

packages/devtools-kit/src/plugins/component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { debounce } from 'perfect-debounce'
22
import { VueAppInstance } from '../types'
33
import { DevToolsEvents, apiHooks, setupDevToolsPlugin } from '../api'
4-
import { devtoolsContext } from '../state'
4+
import { devtoolsContext, devtoolsState } from '../state'
55
import { hook } from '../hook'
66
import { getAppRecord, getComponentId, getComponentInstance } from '../core/component/utils'
77
import { getComponentBoundingRect } from '../core/component/state/bounding-rect'
@@ -96,6 +96,9 @@ export function registerComponentDevToolsPlugin(app: VueAppInstance) {
9696
}, 120)
9797

9898
const componentAddedCleanup = hook.on.componentAdded(async (app, uid, parentUid, component) => {
99+
if (devtoolsState.highPerfModeEnabled)
100+
return
101+
99102
if (app?._instance?.type?.devtools?.hide)
100103
return
101104

@@ -124,6 +127,9 @@ export function registerComponentDevToolsPlugin(app: VueAppInstance) {
124127
})
125128

126129
const componentUpdatedCleanup = hook.on.componentUpdated(async (app, uid, parentUid, component) => {
130+
if (devtoolsState.highPerfModeEnabled)
131+
return
132+
127133
if (app?._instance?.type?.devtools?.hide)
128134
return
129135

@@ -152,6 +158,9 @@ export function registerComponentDevToolsPlugin(app: VueAppInstance) {
152158
debounceSendInspectorState()
153159
})
154160
const componentRemovedCleanup = hook.on.componentRemoved(async (app, uid, parentUid, component) => {
161+
if (devtoolsState.highPerfModeEnabled)
162+
return
163+
155164
if (app?._instance?.type?.devtools?.hide)
156165
return
157166

packages/devtools-kit/src/state/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function initStateFactory() {
1919
commands: [],
2020
vitePluginDetected: false,
2121
activeAppRecordId: null,
22+
highPerfModeEnabled: false,
2223
}
2324
}
2425

packages/devtools-kit/src/types/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface DevToolsState {
1313
tabs: CustomTab[]
1414
commands: CustomCommand[]
1515
activeAppRecordId: string | null
16+
highPerfModeEnabled: boolean
1617
}

packages/vite/src/overlay.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const head = document.getElementsByTagName('head')[0]
1010
setDevToolsEnv({
1111
vitePluginDetected: true,
1212
})
13+
1314
const devtoolsClientUrl = `${vueDevToolsOptions.clientHost || ''}${vueDevToolsOptions.base || '/'}__devtools__/`
1415
setDevToolsClientUrl(devtoolsClientUrl)
1516

0 commit comments

Comments
 (0)