Skip to content

Commit 11876c8

Browse files
fix: redundant re-render and loss of collapsed state for inspector tree/state component (#124)
1 parent a34c3d9 commit 11876c8

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

packages/client/src/components/inspector/InspectorStateField.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const props = withDefaults(defineProps<{
1616
1717
const state = useStateEditorContext()
1818
const bridgeRpc = useDevToolsBridgeRpc()
19-
const value = formatInspectorStateValue(props.data.value)
20-
const type = getInspectorStateValueType(props.data.value)
19+
const value = computed(() => formatInspectorStateValue(props.data.value))
20+
const type = computed(() => getInspectorStateValueType(props.data.value))
2121
const stateFormatClass = computed(() => {
22-
if (type === 'custom')
22+
if (type.value === 'custom')
2323
return `state-format-${(props.data.value as InspectorCustomState)._custom?.type}`
2424
2525
else
@@ -38,7 +38,7 @@ const normalizedValue = computed(() => {
3838
return ''
3939
}
4040
else {
41-
const result = `<span class="state-value-${type}">${value}</span>`
41+
const result = `<span class="state-value-${type.value}">${value.value}</span>`
4242
if (stateTypeName)
4343
return `${result} <span class="text-gray-500">(${stateTypeName})</span>`
4444
@@ -48,7 +48,7 @@ const normalizedValue = computed(() => {
4848
4949
const rawValue = computed(() => {
5050
let value = props.data.value
51-
const isCustom = type === 'custom'
51+
const isCustom = type.value === 'custom'
5252
let inherit = {}
5353
if (isCustom) {
5454
const data = props.data.value as InspectorCustomState
@@ -84,7 +84,7 @@ const normalizedChildField = computed(() => {
8484
editable: props.data.editable,
8585
creating: false,
8686
}))
87-
if (type !== 'custom')
87+
if (type.value !== 'custom')
8888
value = sortByKey(value)
8989
}
9090
else {

packages/client/src/pages/components.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function inspectComponentInspector() {
138138
// #endregion
139139
140140
function selectComponentTree(id: string) {
141+
clearComponentState()
141142
getComponentState(id)
142143
activeComponentId.value = id
143144
}
@@ -170,6 +171,10 @@ function getComponentState(id: string) {
170171
})
171172
}
172173
174+
function clearComponentState() {
175+
activeComponentState.value = {}
176+
}
177+
173178
// #endregion
174179
175180
onDevToolsClientConnected(() => {
@@ -182,7 +187,10 @@ onDevToolsClientConnected(() => {
182187
return
183188
184189
treeNode.value = data.data
185-
componentTreeCollapseMap.value = normalizeComponentTreeCollapsed(data.data)
190+
componentTreeCollapseMap.value = {
191+
...normalizeComponentTreeCollapsed(data.data),
192+
...componentTreeCollapseMap.value,
193+
}
186194
initSelectedComponent(data.data)
187195
}, {
188196
inspectorId: 'components',
@@ -257,9 +265,9 @@ const devtoolsState = useDevToolsState()
257265
</div>
258266
</div>
259267
<p class="x-divider" />
260-
<div h-0 grow overflow-auto p-2 class="no-scrollbar">
268+
<div :key="selectedComponentTree" h-0 grow overflow-auto p-2 class="no-scrollbar">
261269
<InspectorState
262-
v-for="(state, key) in activeComponentState" :id="key" :key="key + Date.now()"
270+
v-for="(state, key) in activeComponentState" :id="key" :key="key"
263271
:node-id="activeComponentId" :data="state" :name="`${key}`" inspector-id="components"
264272
/>
265273
</div>

packages/client/src/pages/pinia.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const tree = ref<{ id: string, label: string, tags: InspectorNodeTag[] }[]>([])
1212
const state = ref<{
1313
inspectorId?: string
1414
state?: InspectorState[]
15+
getters?: InspectorState[]
1516
}>({})
1617
1718
function getPiniaState(nodeId: string) {
@@ -20,7 +21,12 @@ function getPiniaState(nodeId: string) {
2021
})
2122
}
2223
24+
function clearPiniaState() {
25+
state.value = {}
26+
}
27+
2328
watch(selected, () => {
29+
clearPiniaState()
2430
getPiniaState(selected.value)
2531
})
2632
@@ -67,10 +73,10 @@ onDevToolsClientConnected(() => {
6773
</div>
6874
</Pane>
6975
<Pane flex flex-col>
70-
<div h-0 grow overflow-auto p-2 class="no-scrollbar">
76+
<div :key="selected" h-0 grow overflow-auto p-2 class="no-scrollbar">
7177
<InspectorState
7278
v-for="(item, key) in state" :id="key"
73-
:key="key + Date.now()"
79+
:key="key"
7480
inspector-id="pinia"
7581
:node-id="selected" :data="item" :name="`${key}`"
7682
/>

packages/client/src/pages/router.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ function getRouterState(nodeId: string) {
2525
})
2626
}
2727
28+
function clearRouterState() {
29+
state.value = {}
30+
}
31+
2832
watch(selected, () => {
33+
clearRouterState()
2934
getRouterState(selected.value)
3035
})
3136
@@ -70,10 +75,10 @@ onDevToolsClientConnected(() => {
7075
</div>
7176
</Pane>
7277
<Pane flex flex-col>
73-
<div h-0 grow overflow-auto p-2 class="no-scrollbar">
78+
<div :key="selected" h-0 grow overflow-auto p-2 class="no-scrollbar">
7479
<InspectorState
7580
v-for="(item, key) in state" :id="key"
76-
:key="key + Date.now()" :data="item" :name="`${key}`"
81+
:key="key" :data="item" :name="`${key}`"
7782
inspector-id="router"
7883
/>
7984
</div>

0 commit comments

Comments
 (0)