Skip to content

Commit 48f4c6e

Browse files
motianantfu
andauthored
fix(useVModel): clone set to true triggered infinite loop (#3097)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 028a732 commit 48f4c6e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/core/useVModel/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isDef } from '@vueuse/shared'
22
import type { Ref, UnwrapRef, WritableComputedRef } from 'vue-demi'
3-
import { computed, getCurrentInstance, isVue2, ref, watch } from 'vue-demi'
3+
import { computed, getCurrentInstance, isVue2, nextTick, ref, watch } from 'vue-demi'
44
import type { CloneFn } from '../useCloned'
55
import { cloneFnJSON } from '../useCloned'
66

@@ -127,16 +127,23 @@ export function useVModel<P extends object, K extends keyof P, Name extends stri
127127
if (passive) {
128128
const initialValue = getValue()
129129
const proxy = ref<P[K]>(initialValue!)
130+
let isUpdating = false
130131

131132
watch(
132133
() => props[key!],
133-
v => (proxy as any).value = cloneFn(v) as UnwrapRef<P[K]>,
134+
(v) => {
135+
if (!isUpdating) {
136+
isUpdating = true
137+
;(proxy as any).value = cloneFn(v) as UnwrapRef<P[K]>
138+
nextTick(() => isUpdating = false)
139+
}
140+
},
134141
)
135142

136143
watch(
137144
proxy,
138145
(v) => {
139-
if (v !== props[key!] || deep)
146+
if (!isUpdating && (v !== props[key!] || deep))
140147
triggerEmit(v as P[K])
141148
},
142149
{ deep },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy