Skip to content

Commit 19a799c

Browse files
authored
fix(runtime-core): make watchEffect ignore deep option (#765)
1 parent c11905f commit 19a799c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/runtime-core/__tests__/apiWatch.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@ describe('api: watch', () => {
410410
expect(dummy).toBe(1)
411411
})
412412

413+
it('warn and not respect deep option when using effect', async () => {
414+
const arr = ref([1, [2]])
415+
let spy = jest.fn()
416+
watchEffect(
417+
() => {
418+
spy()
419+
return arr
420+
},
421+
// @ts-ignore
422+
{ deep: true }
423+
)
424+
expect(spy).toHaveBeenCalledTimes(1)
425+
;(arr.value[1] as Array<number>)[0] = 3
426+
await nextTick()
427+
expect(spy).toHaveBeenCalledTimes(1)
428+
expect(`"deep" option is only respected`).toHaveBeenWarned()
429+
})
430+
413431
it('onTrack', async () => {
414432
const events: DebuggerEvent[] = []
415433
let dummy

packages/runtime-core/src/apiWatch.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ function doWatch(
139139
if (immediate !== undefined) {
140140
warn(
141141
`watch() "immediate" option is only respected when using the ` +
142-
`watch(source, callback) signature.`
142+
`watch(source, callback, options?) signature.`
143143
)
144144
}
145145
if (deep !== undefined) {
146146
warn(
147147
`watch() "deep" option is only respected when using the ` +
148-
`watch(source, callback) signature.`
148+
`watch(source, callback, options?) signature.`
149149
)
150150
}
151151
}
@@ -186,7 +186,7 @@ function doWatch(
186186
}
187187
}
188188

189-
if (deep) {
189+
if (cb && deep) {
190190
const baseGetter = getter
191191
getter = () => traverse(baseGetter())
192192
}

0 commit comments

Comments
 (0)