Skip to content

Commit 4efbac8

Browse files
committed
fix: post watcher not triggered (fix vuejs#12664)
1 parent 7d4a772 commit 4efbac8

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ packages/server-renderer/client-plugin.js
1212
packages/template-compiler/build.js
1313
packages/template-compiler/browser.js
1414
.vscode
15+
.idea
1516
dist
1617
temp
1718
types/v3-generated.d.ts

src/core/observer/scheduler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function callActivatedHooks(queue) {
156156
*/
157157
export function queueWatcher(watcher: Watcher) {
158158
const id = watcher.id
159-
if (has[id] != null) {
159+
if (id !== Infinity && has[id] != null) {
160160
return
161161
}
162162

test/unit/features/v3/apiWatch.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,51 @@ describe('api: watch', () => {
672672
await nextTick()
673673
expect(dom!.tagName).toBe('P')
674674
})
675+
676+
// #12664
677+
it('flush: post watchers from 2 components should both fire after template refs updated', async () => {
678+
let appPostWatcherTrigger = false
679+
let childComponentPostWatcherTrigger = false
680+
681+
const Child = {
682+
setup() {
683+
const el = ref();
684+
watch(
685+
el,
686+
() => {
687+
childComponentPostWatcherTrigger = true
688+
},
689+
{flush: 'post'}
690+
)
691+
return { el };
692+
},
693+
template: `<div><span ref="el">hello child</span></div>`
694+
}
695+
const App = {
696+
components: { Child },
697+
setup() {
698+
const el = ref();
699+
watch(
700+
el,
701+
() => {
702+
appPostWatcherTrigger = true
703+
},
704+
{flush: 'post'}
705+
)
706+
return { el };
707+
},
708+
template: `<div><Child /><span ref="el">hello app1</span></div>`
709+
}
710+
711+
const container = document.createElement('div')
712+
const root = document.createElement('div')
713+
container.appendChild(root)
714+
new Vue(App).$mount(root)
715+
716+
await nextTick()
717+
expect(appPostWatcherTrigger).toBe(true)
718+
expect(childComponentPostWatcherTrigger).toBe(true)
719+
})
675720

676721
it('deep', async () => {
677722
const state = reactive({

0 commit comments

Comments
 (0)