From b030c8bc7327877efb98aa3d9a58eb287a6ff07a Mon Sep 17 00:00:00 2001 From: linzhe <40790268+linzhe141@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:48:15 +0800 Subject: [PATCH] fix(reactivity): fix triggerRef call on ObjectRefImpl returned by toRef (#11986) close #11982 --- packages/reactivity/src/ref.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index a72e52090dd..1de8b9e3317 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -182,15 +182,18 @@ class RefImpl { * @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref} */ export function triggerRef(ref: Ref): void { - if (__DEV__) { - ;(ref as unknown as RefImpl).dep.trigger({ - target: ref, - type: TriggerOpTypes.SET, - key: 'value', - newValue: (ref as unknown as RefImpl)._value, - }) - } else { - ;(ref as unknown as RefImpl).dep.trigger() + // ref may be an instance of ObjectRefImpl + if ((ref as unknown as RefImpl).dep) { + if (__DEV__) { + ;(ref as unknown as RefImpl).dep.trigger({ + target: ref, + type: TriggerOpTypes.SET, + key: 'value', + newValue: (ref as unknown as RefImpl)._value, + }) + } else { + ;(ref as unknown as RefImpl).dep.trigger() + } } }