Skip to content

Commit 4463da6

Browse files
linzhe141abdullah-wn
authored andcommitted
fix(reactivity): fix triggerRef call on ObjectRefImpl returned by toRef (vuejs#11986)
close vuejs#11982
1 parent 30fd3a8 commit 4463da6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/reactivity/src/ref.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,18 @@ class RefImpl<T = any> {
182182
* @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
183183
*/
184184
export function triggerRef(ref: Ref): void {
185-
if (__DEV__) {
186-
;(ref as unknown as RefImpl).dep.trigger({
187-
target: ref,
188-
type: TriggerOpTypes.SET,
189-
key: 'value',
190-
newValue: (ref as unknown as RefImpl)._value,
191-
})
192-
} else {
193-
;(ref as unknown as RefImpl).dep.trigger()
185+
// ref may be an instance of ObjectRefImpl
186+
if ((ref as unknown as RefImpl).dep) {
187+
if (__DEV__) {
188+
;(ref as unknown as RefImpl).dep.trigger({
189+
target: ref,
190+
type: TriggerOpTypes.SET,
191+
key: 'value',
192+
newValue: (ref as unknown as RefImpl)._value,
193+
})
194+
} else {
195+
;(ref as unknown as RefImpl).dep.trigger()
196+
}
194197
}
195198
}
196199

0 commit comments

Comments
 (0)