From 32f5d5601aea1c6e89b1c296bf13e9ff254b0105 Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Sat, 16 Jul 2022 01:16:31 +0800 Subject: [PATCH 1/2] fix: post watcher not triggered (fix #12664) --- .gitignore | 1 + src/core/observer/scheduler.ts | 6 +++- test/unit/features/v3/apiWatch.spec.ts | 45 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 18c343efc53..4c6ae5bbc66 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ packages/server-renderer/client-plugin.js packages/template-compiler/build.js packages/template-compiler/browser.js .vscode +.idea dist temp types/v3-generated.d.ts diff --git a/src/core/observer/scheduler.ts b/src/core/observer/scheduler.ts index 24e711c36fd..0f807f46f3a 100644 --- a/src/core/observer/scheduler.ts +++ b/src/core/observer/scheduler.ts @@ -156,7 +156,11 @@ function callActivatedHooks(queue) { */ export function queueWatcher(watcher: Watcher) { const id = watcher.id - if (has[id] != null) { + if ( + has[id] != null && + // not skip post watcher which id is Infinity + id !== Infinity + ) { return } diff --git a/test/unit/features/v3/apiWatch.spec.ts b/test/unit/features/v3/apiWatch.spec.ts index c1b301ae9e8..eb07e77dac5 100644 --- a/test/unit/features/v3/apiWatch.spec.ts +++ b/test/unit/features/v3/apiWatch.spec.ts @@ -672,6 +672,51 @@ describe('api: watch', () => { await nextTick() expect(dom!.tagName).toBe('P') }) + + // #12664 + it('flush: post watchers from 2 components should both fire after template refs updated', async () => { + let appPostWatcherTrigger = false + let childComponentPostWatcherTrigger = false + + const Child = { + setup() { + const el = ref(); + watch( + el, + () => { + childComponentPostWatcherTrigger = true + }, + {flush: 'post'} + ) + return { el }; + }, + template: `
hello child
` + } + const App = { + components: { Child }, + setup() { + const el = ref(); + watch( + el, + () => { + appPostWatcherTrigger = true + }, + {flush: 'post'} + ) + return { el }; + }, + template: `
hello app1
` + } + + const container = document.createElement('div') + const root = document.createElement('div') + container.appendChild(root) + new Vue(App).$mount(root) + + await nextTick() + expect(appPostWatcherTrigger).toBe(true) + expect(childComponentPostWatcherTrigger).toBe(true) + }) it('deep', async () => { const state = reactive({ From e7cfe3c2619b5fb6dfa875b7c17236f377888c71 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 16 Jul 2022 08:27:16 -0400 Subject: [PATCH 2/2] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4c6ae5bbc66..18c343efc53 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ packages/server-renderer/client-plugin.js packages/template-compiler/build.js packages/template-compiler/browser.js .vscode -.idea dist temp types/v3-generated.d.ts