fix(watch): fix watching multiple sources containing shallowRef (#5381)
fix #5371
This commit is contained in:
		
							parent
							
								
									04fff05f00
								
							
						
					
					
						commit
						220f255fe9
					
				@ -892,6 +892,21 @@ describe('api: watch', () => {
 | 
				
			|||||||
    expect(sideEffect).toBe(2)
 | 
					    expect(sideEffect).toBe(2)
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('should force trigger on triggerRef when watching multiple sources: shallow ref array', async () => {
 | 
				
			||||||
 | 
					    const v = shallowRef([] as any)
 | 
				
			||||||
 | 
					    const spy = jest.fn()
 | 
				
			||||||
 | 
					    watch([v], () => {
 | 
				
			||||||
 | 
					      spy()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    v.value.push(1)
 | 
				
			||||||
 | 
					    triggerRef(v)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await nextTick()
 | 
				
			||||||
 | 
					    // should trigger now
 | 
				
			||||||
 | 
					    expect(spy).toHaveBeenCalledTimes(1)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // #2125
 | 
					  // #2125
 | 
				
			||||||
  test('watchEffect should not recursively trigger itself', async () => {
 | 
					  test('watchEffect should not recursively trigger itself', async () => {
 | 
				
			||||||
    const spy = jest.fn()
 | 
					    const spy = jest.fn()
 | 
				
			||||||
 | 
				
			|||||||
@ -212,7 +212,7 @@ function doWatch(
 | 
				
			|||||||
    deep = true
 | 
					    deep = true
 | 
				
			||||||
  } else if (isArray(source)) {
 | 
					  } else if (isArray(source)) {
 | 
				
			||||||
    isMultiSource = true
 | 
					    isMultiSource = true
 | 
				
			||||||
    forceTrigger = source.some(isReactive)
 | 
					    forceTrigger = source.some(s => isReactive(s) || isShallow(s))
 | 
				
			||||||
    getter = () =>
 | 
					    getter = () =>
 | 
				
			||||||
      source.map(s => {
 | 
					      source.map(s => {
 | 
				
			||||||
        if (isRef(s)) {
 | 
					        if (isRef(s)) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user