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

Skip to content

fix(kit): inspect error with top-level Proxy value #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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