Skip to content

fix(customFormatter): properly accessing ref value during debugger #12948

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 1 commit into from
Mar 14, 2025
Merged
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: 7 additions & 2 deletions packages/runtime-core/src/customFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
isReadonly,
isRef,
isShallow,
pauseTracking,
resetTracking,
toRaw,
} from '@vue/reactivity'
import { EMPTY_OBJ, extend, isArray, isFunction, isObject } from '@vue/shared'
Expand Down Expand Up @@ -34,13 +36,16 @@ export function initCustomFormatter(): void {
if (obj.__isVue) {
return ['div', vueStyle, `VueInstance`]
} else if (isRef(obj)) {
// avoid tracking during debugger accessing
pauseTracking()
const value = obj.value
resetTracking()
return [
'div',
{},
['span', vueStyle, genRefFlag(obj)],
'<',
// avoid debugger accessing value affecting behavior
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if it wasn't intentional to completely avoid calling the getter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was originally obj.value, but it was changed to the current implementation in https://github.com/vuejs/core/pull/10397/files#diff-95f4e5cf8305f906512f733429443451392894309ce012c5a70216f9e578738eL41. I think this change may not have considered the case where the value of ._value is undefined when .value is not accessed. So I think we should continue using obj.value, but not track it.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. I thought that maybe displaying undefined for a value that was never accessed before was the expected behavior

formatValue('_value' in obj ? obj._value : obj),
formatValue(value),
`>`,
]
} else if (isReactive(obj)) {
Expand Down