@@ -63,12 +63,18 @@ export function setRef(
63
63
const oldRef = oldRawRef && ( oldRawRef as VNodeNormalizedRefAtom ) . r
64
64
const refs = owner . refs === EMPTY_OBJ ? ( owner . refs = { } ) : owner . refs
65
65
const setupState = owner . setupState
66
+ const canSetSetupRef =
67
+ setupState === EMPTY_OBJ
68
+ ? ( ) => false
69
+ : ( key : string ) =>
70
+ hasOwn ( setupState , key ) &&
71
+ ! ( Object . getOwnPropertyDescriptor ( refs , key ) || EMPTY_OBJ ) . get
66
72
67
73
// dynamic ref changed. unset old ref
68
74
if ( oldRef != null && oldRef !== ref ) {
69
75
if ( isString ( oldRef ) ) {
70
76
refs [ oldRef ] = null
71
- if ( hasOwn ( setupState , oldRef ) ) {
77
+ if ( canSetSetupRef ( oldRef ) ) {
72
78
setupState [ oldRef ] = null
73
79
}
74
80
} else if ( isRef ( oldRef ) ) {
@@ -81,11 +87,12 @@ export function setRef(
81
87
} else {
82
88
const _isString = isString ( ref )
83
89
const _isRef = isRef ( ref )
90
+
84
91
if ( _isString || _isRef ) {
85
92
const doSet = ( ) => {
86
93
if ( rawRef . f ) {
87
94
const existing = _isString
88
- ? hasOwn ( setupState , ref )
95
+ ? canSetSetupRef ( ref )
89
96
? setupState [ ref ]
90
97
: refs [ ref ]
91
98
: ref . value
@@ -95,7 +102,7 @@ export function setRef(
95
102
if ( ! isArray ( existing ) ) {
96
103
if ( _isString ) {
97
104
refs [ ref ] = [ refValue ]
98
- if ( hasOwn ( setupState , ref ) ) {
105
+ if ( canSetSetupRef ( ref ) ) {
99
106
setupState [ ref ] = refs [ ref ]
100
107
}
101
108
} else {
@@ -108,7 +115,7 @@ export function setRef(
108
115
}
109
116
} else if ( _isString ) {
110
117
refs [ ref ] = value
111
- if ( hasOwn ( setupState , ref ) ) {
118
+ if ( canSetSetupRef ( ref ) ) {
112
119
setupState [ ref ] = value
113
120
}
114
121
} else if ( _isRef ) {
0 commit comments