Skip to content

Commit

Permalink
fix: post watcher not triggered (fix vuejs#12664)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorTour committed Jul 16, 2022
1 parent 7d4a772 commit 34e4239
Show file tree
Hide file tree
Showing 4 changed files with 4,032 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -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
6 changes: 5 additions & 1 deletion src/core/observer/scheduler.ts
Expand Up @@ -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
}

Expand Down
45 changes: 45 additions & 0 deletions test/unit/features/v3/apiWatch.spec.ts
Expand Up @@ -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: `<div><span ref="el">hello child</span></div>`
}
const App = {
components: { Child },
setup() {
const el = ref();
watch(
el,
() => {
appPostWatcherTrigger = true
},
{flush: 'post'}
)
return { el };
},
template: `<div><Child /><span ref="el">hello app1</span></div>`
}

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({
Expand Down

0 comments on commit 34e4239

Please sign in to comment.