Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit fe20d1c

Browse files
feat: introducting rerender trace feature (#153)
--------- Co-authored-by: alexzhang1030 <[email protected]>
1 parent ed2275e commit fe20d1c

38 files changed

+1656
-98
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: npm i -g @antfu/ni
2626
- name: Install
2727
run: nci
28+
- name: Test
29+
run: nr test
2830
- name: Build
2931
run: nr build
3032
- name: Lint

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ export default defineConfig({
117117
### Options
118118

119119
```ts
120+
interface AnalyzeOptions {
121+
/**
122+
* @default true
123+
*/
124+
rerenderTrace: boolean
125+
}
126+
120127
interface VitePluginVueDevToolsOptions {
121128
/**
122129
* append an import to the module id ending with `appendTo` instead of adding a script into body
@@ -125,6 +132,14 @@ interface VitePluginVueDevToolsOptions {
125132
* WARNING: only set this if you know exactly what it does.
126133
*/
127134
appendTo?: string | RegExp
135+
/**
136+
* Enable Vue DevTools to analyze the codebase by using Babel
137+
* @default
138+
* {
139+
* rerenderTrace: true, // enable rerenderTrace feature
140+
* }
141+
*/
142+
analyze?: Partial<AnalyzeOptions>
128143
}
129144
```
130145

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"prepublishOnly": "npm run build",
5555
"release": "bumpp -r",
5656
"dep:up": "taze -I major",
57-
"prepare": "simple-git-hooks"
57+
"prepare": "simple-git-hooks",
58+
"test": "vitest"
5859
},
5960
"peerDependencies": {
6061
"vite": "^3.1.0 || ^4.0.0-0"
@@ -76,6 +77,7 @@
7677
"typescript": "^5.1.6",
7778
"unbuild": "^1.2.1",
7879
"vite": "^4.4.4",
80+
"vitest": "^0.33.0",
7981
"vue": "^3.3.4"
8082
},
8183
"simple-git-hooks": {

packages/client/App.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ hookApi.hook.on('init:vue:app', () => {
1717
// mark client as loaded
1818
client.value.markClientLoaded()
1919
// listen hook
20-
hookApi.produce()
20+
hookApi.subscribe()
2121
// perf timeline
2222
// close perf timeline to avoid performance issue (#9)
2323
// initPerfTimeline(categorizedHookBuffer.perf)
24-
// consume hook buffer
25-
hookApi.consume(categorizedHookBuffer.component ?? [])
24+
// publish hook buffer
25+
hookApi.publish(categorizedHookBuffer.component ?? [])
2626
// init routes
2727
initRoutes(categorizedHookBuffer.router ?? [])
2828
// init pinia

packages/client/logic/components/data.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function processState(instance: any): any {
167167
}))
168168
}
169169

170-
function processSetupState(instance: any) {
170+
export function processSetupState(instance: any) {
171171
const raw = instance.devtoolsRawSetupState || {}
172172
return Object.keys(instance.setupState)
173173
.filter(key => !vueBuiltins.includes(key) && key.split(/(?=[A-Z])/)[0] !== 'use')
@@ -226,14 +226,14 @@ function isReadOnly(raw: any): boolean {
226226
return !!raw.__v_isReadonly
227227
}
228228

229-
function toRaw(value: any) {
229+
export function toRaw(value: any) {
230230
if (value?.__v_raw)
231231
return value.__v_raw
232232

233233
return value
234234
}
235235

236-
function getSetupStateInfo(raw: any) {
236+
export function getSetupStateInfo(raw: any) {
237237
return {
238238
ref: isRef(raw),
239239
computed: isComputed(raw),
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { ComponentWalker, InstanceMap } from './tree'
2-
export { getInstanceState, getInstanceDetails } from './data'
2+
export { getInstanceState, processSetupState, getInstanceDetails, getSetupStateInfo } from './data'
33
export { getInstanceOrVnodeRect, getRootElementsFromComponentInstance } from './el'
44
export { getInstanceName } from './util'

packages/client/logic/format-state.ts

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export interface StateType {
2727
rawDisplay?: string
2828
recursive: boolean
2929
}
30-
// function isReactive(raw: any): boolean {
31-
// return !!raw.__ob__
32-
// }
3330

3431
export function formatStateType(value: unknown): StateType {
3532
// Vue

packages/client/logic/hook.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1+
import { DevToolsHooks } from '@vite-plugin-vue-devtools/core'
12
import { updatePinia } from './pinia'
23
import { instance, updateApp, app as vueApp } from './app'
34
import { useDevToolsClient } from './client'
45

5-
enum DevtoolsHooks {
6-
APP_INIT = 'app:init',
7-
COMPONENT_UPDATED = 'component:updated',
8-
COMPONENT_ADDED = 'component:added',
9-
COMPONENT_REMOVED = 'component:removed',
10-
COMPONENT_EMIT = 'component:emit',
11-
}
12-
136
function hideInDevtools(component) {
147
return component?.root?.type?.devtools?.hide
158
}
169

1710
const client = useDevToolsClient()
1811

19-
function produceHook() {
12+
function subscribeHook() {
2013
const client = useDevToolsClient()
2114
const hook = client.value.hook
22-
hook.on(DevtoolsHooks.APP_INIT, (app) => {
15+
hook.on(DevToolsHooks.APP_INIT, (app) => {
2316
if (app?._vueDevtools_hidden_)
2417
return
2518
vueApp.value = app
@@ -30,7 +23,7 @@ function produceHook() {
3023
return (!app || (typeof uid !== 'number' && !uid) || !component || hideInDevtools(component))
3124
}
3225

33-
hook.on(DevtoolsHooks.COMPONENT_UPDATED, (app, uid, parentUid, component) => {
26+
hook.on(DevToolsHooks.COMPONENT_UPDATED, (app, uid, parentUid, component) => {
3427
updatePinia(component)
3528

3629
if (skipCollect(app, uid, component))
@@ -39,7 +32,7 @@ function produceHook() {
3932
updateApp(app, component)
4033
})
4134

42-
hook.on(DevtoolsHooks.COMPONENT_ADDED, (app, uid, parentUid, component) => {
35+
hook.on(DevToolsHooks.COMPONENT_ADDED, (app, uid, parentUid, component) => {
4336
updatePinia(component)
4437

4538
if (skipCollect(app, uid, component))
@@ -49,7 +42,7 @@ function produceHook() {
4942
updateApp(app, component)
5043
})
5144

52-
hook.on(DevtoolsHooks.COMPONENT_REMOVED, (app, uid, parentUid, component) => {
45+
hook.on(DevToolsHooks.COMPONENT_REMOVED, (app, uid, parentUid, component) => {
5346
updatePinia(component)
5447

5548
if (skipCollect(app, uid, component))
@@ -60,7 +53,7 @@ function produceHook() {
6053
updateApp(app, component)
6154
})
6255

63-
hook.on(DevtoolsHooks.COMPONENT_EMIT, (app, uid, parentUid, component) => {
56+
hook.on(DevToolsHooks.COMPONENT_EMIT, (app, uid, parentUid, component) => {
6457
updatePinia(component)
6558

6659
if (skipCollect(app, uid, component))
@@ -72,7 +65,7 @@ function produceHook() {
7265
})
7366
}
7467

75-
function ConsumeHook(buffer: [string, Record<string, any>][]) {
68+
function publishHook(buffer: [string, Record<string, any>][]) {
7669
buffer.forEach(([_, { app, component }]) => {
7770
updatePinia(component)
7871
updateApp(app, component)
@@ -81,6 +74,6 @@ function ConsumeHook(buffer: [string, Record<string, any>][]) {
8174

8275
export const hookApi = {
8376
hook: client.value.hook,
84-
produce: produceHook,
85-
consume: ConsumeHook,
77+
subscribe: subscribeHook,
78+
publish: publishHook,
8679
}

0 commit comments

Comments
 (0)