Skip to content

Commit c1e14f2

Browse files
fix(client): deserialize issue on editing custom property (#144)
1 parent c8eba5a commit c1e14f2

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

packages/client/src/components/inspector/InspectorDataField/Actions.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import { VueButton, VueDropdown, VueDropdownButton, VueIcon, VTooltip as vTooltip } from '@vue/devtools-ui'
3+
import { getRawValue } from '@vue/devtools-kit'
34
import type { InspectorState, InspectorStateEditorPayload } from '@vue/devtools-kit'
45
import type { ButtonProps } from '@vue/devtools-ui/dist/types/src/components/Button'
56
import { useDevToolsBridgeRpc } from '@vue/devtools-core'
@@ -28,9 +29,8 @@ const { copy, isSupported } = useClipboard()
2829
2930
const popupVisible = ref(false)
3031
31-
const dataType = computed(() => {
32-
return typeof props.data.value
33-
})
32+
const rawValue = computed(() => getRawValue(props.data.value).value)
33+
const dataType = computed(() => typeof rawValue.value)
3434
3535
const iconButtonProps = {
3636
flat: true,
@@ -77,7 +77,7 @@ function quickEdit(v: unknown, remove: boolean = false) {
7777
v-tooltip="{
7878
content: 'Add new value',
7979
}" v-bind="iconButtonProps" :class="buttonClass" @click.stop="
80-
$emit('addNewProp', Array.isArray(data.value) ? 'array' : 'object')"
80+
$emit('addNewProp', Array.isArray(rawValue) ? 'array' : 'object')"
8181
>
8282
<template #icon>
8383
<VueIcon icon="i-material-symbols-add-circle-rounded" />
@@ -87,28 +87,28 @@ function quickEdit(v: unknown, remove: boolean = false) {
8787
<!-- checkbox, button value only -->
8888
<VueButton
8989
v-if="dataType === 'boolean'" v-bind="iconButtonProps" :class="buttonClass"
90-
@click="quickEdit(!data.value)"
90+
@click="quickEdit(!rawValue)"
9191
>
9292
<template #icon>
93-
<VueIcon :icon="data.value ? 'i-material-symbols-check-box-sharp' : 'i-material-symbols-check-box-outline-blank-sharp'" />
93+
<VueIcon :icon="rawValue ? 'i-material-symbols-check-box-sharp' : 'i-material-symbols-check-box-outline-blank-sharp'" />
9494
</template>
9595
</VueButton>
9696
<!-- increment/decrement button, numeric value only -->
9797
<template v-else-if="dataType === 'number'">
98-
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((data.value as number) + 1)">
98+
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((rawValue as number) + 1)">
9999
<template #icon>
100100
<VueIcon icon="i-carbon-add" />
101101
</template>
102102
</VueButton>
103-
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((data.value as number) - 1)">
103+
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((rawValue as number) - 1)">
104104
<template #icon>
105105
<VueIcon icon="i-carbon-subtract" />
106106
</template>
107107
</VueButton>
108108
</template>
109109
</template>
110110
<!-- delete prop, only appear if depth > 0 -->
111-
<VueButton v-if="!props.disableEdit && depth > 0" v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit(data.value, true)">
111+
<VueButton v-if="!props.disableEdit && depth > 0" v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit(rawValue, true)">
112112
<template #icon>
113113
<VueIcon icon="i-material-symbols-delete-rounded" />
114114
</template>
@@ -128,7 +128,7 @@ function quickEdit(v: unknown, remove: boolean = false) {
128128
<template #popper>
129129
<div class="w160px py5px">
130130
<VueDropdownButton
131-
@click="copy(dataType === 'object' ? JSON.stringify(data.value) : data.value.toString())"
131+
@click="copy(dataType === 'object' ? JSON.stringify(rawValue) : rawValue.toString())"
132132
>
133133
<template #icon>
134134
<VueIcon icon="i-material-symbols-copy-all-rounded" class="mt4px" />

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { InspectorCustomState, InspectorState, InspectorStateEditorPayload } from '@vue/devtools-kit'
33
import { sortByKey } from '@vue/devtools-shared'
4-
import { formatInspectorStateValue, getInspectorStateValueType } from '@vue/devtools-kit'
4+
import { formatInspectorStateValue, getInspectorStateValueType, getRawValue } from '@vue/devtools-kit'
55
import { useDevToolsBridgeRpc } from '@vue/devtools-core'
66
import Actions from './InspectorDataField/Actions.vue'
77
import type { EditorAddNewPropType } from '~/composables/inspector'
@@ -47,22 +47,7 @@ const normalizedValue = computed(() => {
4747
}
4848
})
4949
50-
const rawValue = computed(() => {
51-
let value = props.data.value
52-
const isCustom = type.value === 'custom'
53-
let inherit = {}
54-
if (isCustom) {
55-
const data = props.data.value as InspectorCustomState
56-
inherit = data._custom?.fields || {}
57-
value = data._custom?.value as string
58-
}
59-
// @ts-expect-error @TODO: type
60-
if (value && value._isArray)
61-
// @ts-expect-error @TODO: type
62-
value = value.items
63-
64-
return { value, inherit }
65-
})
50+
const rawValue = computed(() => getRawValue(props.data.value))
6651
6752
const normalizedChildField = computed(() => {
6853
let { value, inherit } = rawValue.value
@@ -112,12 +97,10 @@ const { editingType, editing, editingText, toggleEditing, nodeId } = useStateEdi
11297
11398
watch(() => editing.value, (v) => {
11499
if (v) {
115-
const value = props.data.value
116-
if (typeof value === 'object') {
117-
editingText.value = JSON.stringify(value)
118-
return
119-
}
120-
editingText.value = value.toString()
100+
const { value } = rawValue.value
101+
editingText.value = typeof value === 'object'
102+
? JSON.stringify(value)
103+
: value.toString()
121104
}
122105
else {
123106
editingText.value = ''
@@ -146,7 +129,7 @@ const { addNewProp: addNewPropApi, draftingNewProp, resetDrafting } = useStateEd
146129
function addNewProp(type: EditorAddNewPropType) {
147130
if (!isExpanded.value)
148131
toggleCollapse()
149-
addNewPropApi(type, props.data.value)
132+
addNewPropApi(type, rawValue.value.value)
150133
}
151134
152135
function submitDrafting() {

packages/devtools-kit/src/core/component/state/format.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InspectorCustomState, InspectorState } from '../types'
12
import { INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED, rawTypeRE, specialTypeRE } from './constants'
23
import { isPlainObject } from './is'
34
import { escape, internalStateTokenToString } from './util'
@@ -82,3 +83,19 @@ export function formatInspectorStateValue(value, quotes = false) {
8283
}
8384
return value
8485
}
86+
87+
export function getRawValue(value: InspectorState['value']) {
88+
const isCustom = getInspectorStateValueType(value) === 'custom'
89+
let inherit = {}
90+
if (isCustom) {
91+
const data = value as InspectorCustomState
92+
inherit = data._custom?.fields || {}
93+
value = data._custom?.value as string
94+
}
95+
// @ts-expect-error @TODO: type
96+
if (value && value._isArray)
97+
// @ts-expect-error @TODO: type
98+
value = value.items
99+
100+
return { value, inherit }
101+
}

packages/devtools-kit/src/shared/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatInspectorStateValue, getInspectorStateValueType } from '../core/component/state/format'
1+
import { formatInspectorStateValue, getInspectorStateValueType, getRawValue } from '../core/component/state/format'
22
import { stringifyReplacer } from '../core/component/state/replacer'
33
import { reviver } from '../core/component/state/reviver'
44
import { parseCircularAutoChunks, stringifyCircularAutoChunks } from './transfer'
@@ -19,4 +19,5 @@ export function parse(data: string, revive = false) {
1919
export {
2020
formatInspectorStateValue,
2121
getInspectorStateValueType,
22+
getRawValue,
2223
}

0 commit comments

Comments
 (0)