mirror of https://github.com/vuejs/core.git
				
				
				
			fix(watch): for immediate watch with single source, ensure cb is called with undefined as oldValue (#7075)
fix: #7074
This commit is contained in:
		
							parent
							
								
									9a816dcec0
								
							
						
					
					
						commit
						5dc593ba28
					
				|  | @ -745,7 +745,7 @@ describe('api: watch', () => { | |||
|     const state = ref() | ||||
|     const spy = jest.fn() | ||||
|     watch(() => state.value, spy, { immediate: true }) | ||||
|     expect(spy).toHaveBeenCalled() | ||||
|     expect(spy).toHaveBeenCalledWith(undefined, undefined, expect.any(Function)) | ||||
|     state.value = 3 | ||||
|     await nextTick() | ||||
|     expect(spy).toHaveBeenCalledTimes(2) | ||||
|  |  | |||
|  | @ -333,8 +333,9 @@ function doWatch( | |||
|         callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ | ||||
|           newValue, | ||||
|           // pass undefined as the old value when it's changed for the first time
 | ||||
|           oldValue === INITIAL_WATCHER_VALUE || | ||||
|           (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE) | ||||
|           oldValue === INITIAL_WATCHER_VALUE  | ||||
|             ? undefined | ||||
|             : (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE) | ||||
|               ? [] | ||||
|               : oldValue, | ||||
|           onCleanup | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue