Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4539ee9

Browse files
fix(kit): inspect error with top-level Proxy value (#701)
Co-authored-by: Alex <[email protected]>
1 parent d8dc8fe commit 4539ee9

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

packages/applet/src/components/state/StateFieldViewer.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,13 @@ async function submitDrafting() {
279279
--at-apply: 'text-#aaa';
280280
}
281281
}
282+
283+
// native error
284+
:deep(.native.Error-state-type) {
285+
--at-apply: 'text-red-500';
286+
&::before {
287+
content: 'Error:';
288+
margin-right: 4px;
289+
}
290+
}
282291
</style>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ function processSetupState(instance: VueAppInstance) {
139139
const value = returnError(() => toRaw(instance.setupState[key])) as unknown as {
140140
render: Function
141141
__asyncLoader: Function
142-
143142
}
143+
const accessError = value instanceof Error
144144

145145
const rawData = raw[key] as {
146146
effect: {
@@ -151,13 +151,14 @@ function processSetupState(instance: VueAppInstance) {
151151

152152
let result: Partial<InspectorState>
153153

154-
let isOtherType = typeof value === 'function'
154+
let isOtherType = accessError
155+
|| typeof value === 'function'
155156
|| (ensurePropertyExists(value, 'render') && typeof value.render === 'function') // Components
156157
|| (ensurePropertyExists(value, '__asyncLoader') && typeof value.__asyncLoader === 'function') // Components
157158
|| (typeof value === 'object' && value && ('setup' in value || 'props' in value)) // Components
158159
|| /^v[A-Z]/.test(key) // Directives
159160

160-
if (rawData) {
161+
if (rawData && !accessError) {
161162
const info = getSetupStateType(rawData)
162163

163164
const { stateType, stateTypeName } = getStateTypeAndName(info)

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,21 @@ export function sanitize(data: unknown) {
7272
}
7373

7474
export function getSetupStateType(raw) {
75-
return {
76-
ref: isRef(raw),
77-
computed: isComputed(raw),
78-
reactive: isReactive(raw),
79-
readonly: isReadOnly(raw),
75+
try {
76+
return {
77+
ref: isRef(raw),
78+
computed: isComputed(raw),
79+
reactive: isReactive(raw),
80+
readonly: isReadOnly(raw),
81+
}
82+
}
83+
catch {
84+
return {
85+
ref: false,
86+
computed: false,
87+
reactive: false,
88+
readonly: false,
89+
}
8090
}
8191
}
8292

packages/playground/basic/src/pages/Home.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ function trigger() {
2222
}
2323
2424
const toRefObj = toRefs(obj)
25+
const topLevelProxy = new Proxy({
26+
foo() {
27+
return 'foo'
28+
},
29+
}, {
30+
get(target, key) {
31+
return target[key]()
32+
},
33+
})
2534
</script>
2635

2736
<template>

0 commit comments

Comments
 (0)