Skip to content

Commit

Permalink
fix(kit): inspect error with top-level Proxy value (#701)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex <[email protected]>
  • Loading branch information
FoundTheWOUT and alexzhang1030 authored Nov 27, 2024
1 parent d8dc8fe commit 4539ee9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/applet/src/components/state/StateFieldViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,13 @@ async function submitDrafting() {
--at-apply: 'text-#aaa';
}
}
// native error
:deep(.native.Error-state-type) {
--at-apply: 'text-red-500';
&::before {
content: 'Error:';
margin-right: 4px;
}
}
</style>
7 changes: 4 additions & 3 deletions packages/devtools-kit/src/core/component/state/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ function processSetupState(instance: VueAppInstance) {
const value = returnError(() => toRaw(instance.setupState[key])) as unknown as {
render: Function
__asyncLoader: Function

}
const accessError = value instanceof Error

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

let result: Partial<InspectorState>

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

if (rawData) {
if (rawData && !accessError) {
const info = getSetupStateType(rawData)

const { stateType, stateTypeName } = getStateTypeAndName(info)
Expand Down
20 changes: 15 additions & 5 deletions packages/devtools-kit/src/core/component/state/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,21 @@ export function sanitize(data: unknown) {
}

export function getSetupStateType(raw) {
return {
ref: isRef(raw),
computed: isComputed(raw),
reactive: isReactive(raw),
readonly: isReadOnly(raw),
try {
return {
ref: isRef(raw),
computed: isComputed(raw),
reactive: isReactive(raw),
readonly: isReadOnly(raw),
}
}
catch {
return {
ref: false,
computed: false,
reactive: false,
readonly: false,
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/playground/basic/src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function trigger() {
}
const toRefObj = toRefs(obj)
const topLevelProxy = new Proxy({
foo() {
return 'foo'
},
}, {
get(target, key) {
return target[key]()
},
})
</script>

<template>
Expand Down

0 comments on commit 4539ee9

Please sign in to comment.