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

feat: introducting rerender trace feature #153

Merged
merged 35 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
664b2d9
feat: init
webfansplz Jul 18, 2023
b4ff7e0
chore: update
webfansplz Jul 19, 2023
a8e2dcc
feat: rerender trace page
webfansplz Jul 19, 2023
2a1b89a
feat(compiler): init
alexzhang1030 Jul 20, 2023
62dbb42
chore: remove unused config
alexzhang1030 Jul 20, 2023
83e5055
feat(compiler): analyze import statement by regex
alexzhang1030 Jul 20, 2023
1b3dc8e
feat(compiler): supplement import
alexzhang1030 Jul 20, 2023
6384e9f
feat(compiler): track-rerender inject code
alexzhang1030 Jul 20, 2023
ff0de39
fix: build error
alexzhang1030 Jul 20, 2023
b2f7a25
feat(compiler): sfc inject code
alexzhang1030 Jul 20, 2023
b4ea3fe
fix(node): vite transform hook
alexzhang1030 Jul 20, 2023
b5c29a4
fix(node): transform hook logic
alexzhang1030 Jul 20, 2023
42224b7
fix(test): test case parameters
alexzhang1030 Jul 20, 2023
7f3c7a8
chore: update
webfansplz Jul 20, 2023
11b7b11
chore: update
webfansplz Jul 20, 2023
f012a4d
feat(compiler/trace-rerender): support non-setup script
alexzhang1030 Jul 21, 2023
542b932
fix(compiler): insert improt loc error when normal script
alexzhang1030 Jul 21, 2023
75f809d
chore: update test name
alexzhang1030 Jul 21, 2023
941b7b1
chore: update test snapshot
alexzhang1030 Jul 21, 2023
0469cef
refactor: readable variable name
alexzhang1030 Jul 21, 2023
c2544ef
chore: use constants instead of magic string
alexzhang1030 Jul 21, 2023
f71953b
feat: add a analyze option `exclude`
alexzhang1030 Jul 21, 2023
5266ab4
feat(compiler): support script file
alexzhang1030 Jul 21, 2023
2781e35
chore: rename rerender -> rerenderTrace
alexzhang1030 Jul 21, 2023
5a1e63b
perf: skip script files that are not include defineComponent
alexzhang1030 Jul 21, 2023
f292ac1
chore: move analyzeOptionsDefault to core package
alexzhang1030 Jul 21, 2023
5d1c2df
workflow: add test step
alexzhang1030 Jul 21, 2023
30c8c38
chore: update
webfansplz Jul 21, 2023
597a75d
Merge branch 'feat-trace-rerender' of https://github.com/webfansplz/v…
webfansplz Jul 21, 2023
081ac73
fix(tab): update tabs when client tabs is outdated
alexzhang1030 Jul 21, 2023
bb2cbe7
chore: prettify code
alexzhang1030 Jul 21, 2023
ca409f7
chore: update
webfansplz Jul 21, 2023
d8f1846
chore: update
webfansplz Jul 21, 2023
c8dd2c4
refactor: cases that disable analyze
alexzhang1030 Jul 21, 2023
5c7601a
chore: update
webfansplz Jul 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: npm i -g @antfu/ni
- name: Install
run: nci
- name: Test
run: nr test
- name: Build
run: nr build
- name: Lint
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export default defineConfig({
### Options

```ts
interface AnalyzeOptions {
/**
* @default true
*/
rerenderTrace: boolean
}

interface VitePluginVueDevToolsOptions {
/**
* append an import to the module id ending with `appendTo` instead of adding a script into body
Expand All @@ -122,6 +129,14 @@ interface VitePluginVueDevToolsOptions {
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string | RegExp
/**
* Enable Vue DevTools to analyze the codebase by using Babel
* @default
* {
* rerenderTrace: true, // enable rerenderTrace feature
* }
*/
analyze?: Partial<AnalyzeOptions>
}
```

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"prepublishOnly": "npm run build",
"release": "bumpp -r",
"dep:up": "taze -I major",
"prepare": "simple-git-hooks"
"prepare": "simple-git-hooks",
"test": "vitest"
},
"peerDependencies": {
"vite": "^3.1.0 || ^4.0.0-0"
Expand All @@ -76,6 +77,7 @@
"typescript": "^5.1.6",
"unbuild": "^1.2.1",
"vite": "^4.4.4",
"vitest": "^0.33.0",
"vue": "^3.3.4"
},
"simple-git-hooks": {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ hookApi.hook.on('init:vue:app', () => {
// mark client as loaded
client.value.markClientLoaded()
// listen hook
hookApi.produce()
hookApi.subscribe()
// perf timeline
// close perf timeline to avoid performance issue (#9)
// initPerfTimeline(categorizedHookBuffer.perf)
// consume hook buffer
hookApi.consume(categorizedHookBuffer.component ?? [])
// publish hook buffer
hookApi.publish(categorizedHookBuffer.component ?? [])
// init routes
initRoutes(categorizedHookBuffer.router ?? [])
// init pinia
Expand Down
6 changes: 3 additions & 3 deletions packages/client/logic/components/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function processState(instance: any): any {
}))
}

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

function toRaw(value: any) {
export function toRaw(value: any) {
if (value?.__v_raw)
return value.__v_raw

return value
}

function getSetupStateInfo(raw: any) {
export function getSetupStateInfo(raw: any) {
return {
ref: isRef(raw),
computed: isComputed(raw),
Expand Down
2 changes: 1 addition & 1 deletion packages/client/logic/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ComponentWalker, InstanceMap } from './tree'
export { getInstanceState, getInstanceDetails } from './data'
export { getInstanceState, processSetupState, getInstanceDetails, getSetupStateInfo } from './data'
export { getInstanceOrVnodeRect, getRootElementsFromComponentInstance } from './el'
export { getInstanceName } from './util'
3 changes: 0 additions & 3 deletions packages/client/logic/format-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export interface StateType {
rawDisplay?: string
recursive: boolean
}
// function isReactive(raw: any): boolean {
// return !!raw.__ob__
// }

export function formatStateType(value: unknown): StateType {
// Vue
Expand Down
27 changes: 10 additions & 17 deletions packages/client/logic/hook.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { DevToolsHooks } from '@vite-plugin-vue-devtools/core'
import { updatePinia } from './pinia'
import { instance, updateApp, app as vueApp } from './app'
import { useDevToolsClient } from './client'

enum DevtoolsHooks {
APP_INIT = 'app:init',
COMPONENT_UPDATED = 'component:updated',
COMPONENT_ADDED = 'component:added',
COMPONENT_REMOVED = 'component:removed',
COMPONENT_EMIT = 'component:emit',
}

function hideInDevtools(component) {
return component?.root?.type?.devtools?.hide
}

const client = useDevToolsClient()

function produceHook() {
function subscribeHook() {
const client = useDevToolsClient()
const hook = client.value.hook
hook.on(DevtoolsHooks.APP_INIT, (app) => {
hook.on(DevToolsHooks.APP_INIT, (app) => {
if (app?._vueDevtools_hidden_)
return
vueApp.value = app
Expand All @@ -30,7 +23,7 @@ function produceHook() {
return (!app || (typeof uid !== 'number' && !uid) || !component || hideInDevtools(component))
}

hook.on(DevtoolsHooks.COMPONENT_UPDATED, (app, uid, parentUid, component) => {
hook.on(DevToolsHooks.COMPONENT_UPDATED, (app, uid, parentUid, component) => {
updatePinia(component)

if (skipCollect(app, uid, component))
Expand All @@ -39,7 +32,7 @@ function produceHook() {
updateApp(app, component)
})

hook.on(DevtoolsHooks.COMPONENT_ADDED, (app, uid, parentUid, component) => {
hook.on(DevToolsHooks.COMPONENT_ADDED, (app, uid, parentUid, component) => {
updatePinia(component)

if (skipCollect(app, uid, component))
Expand All @@ -49,7 +42,7 @@ function produceHook() {
updateApp(app, component)
})

hook.on(DevtoolsHooks.COMPONENT_REMOVED, (app, uid, parentUid, component) => {
hook.on(DevToolsHooks.COMPONENT_REMOVED, (app, uid, parentUid, component) => {
updatePinia(component)

if (skipCollect(app, uid, component))
Expand All @@ -60,7 +53,7 @@ function produceHook() {
updateApp(app, component)
})

hook.on(DevtoolsHooks.COMPONENT_EMIT, (app, uid, parentUid, component) => {
hook.on(DevToolsHooks.COMPONENT_EMIT, (app, uid, parentUid, component) => {
updatePinia(component)

if (skipCollect(app, uid, component))
Expand All @@ -72,7 +65,7 @@ function produceHook() {
})
}

function ConsumeHook(buffer: [string, Record<string, any>][]) {
function publishHook(buffer: [string, Record<string, any>][]) {
buffer.forEach(([_, { app, component }]) => {
updatePinia(component)
updateApp(app, component)
Expand All @@ -81,6 +74,6 @@ function ConsumeHook(buffer: [string, Record<string, any>][]) {

export const hookApi = {
hook: client.value.hook,
produce: produceHook,
consume: ConsumeHook,
subscribe: subscribeHook,
publish: publishHook,
}
Loading