Skip to content

Commit

Permalink
fix: fix post watcher fire timing on nested app mounts
Browse files Browse the repository at this point in the history
close #10005
  • Loading branch information
yyx990803 committed Jan 8, 2024
1 parent d9162df commit 3c3561e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
32 changes: 32 additions & 0 deletions packages/runtime-core/__tests__/apiCreateApp.spec.ts
Expand Up @@ -5,12 +5,15 @@ import {
getCurrentInstance,
h,
inject,
nextTick,
nodeOps,
onMounted,
provide,
ref,
resolveComponent,
resolveDirective,
serializeInner,
watch,
withDirectives,
} from '@vue/runtime-test'

Expand Down Expand Up @@ -551,6 +554,35 @@ describe('api: createApp', () => {
).not.toHaveBeenWarned()
})

// #10005
test('flush order edge case on nested createApp', async () => {
const order: string[] = []
const App = defineComponent({
setup(props) {
const message = ref('m1')
watch(
message,
() => {
order.push('post watcher')
},
{ flush: 'post' },
)
onMounted(() => {
message.value = 'm2'
createApp(() => '').mount(nodeOps.createElement('div'))
})
return () => {
order.push('render')
return h('div', [message.value])
}
},
})

createApp(App).mount(nodeOps.createElement('div'))
await nextTick()
expect(order).toMatchObject(['render', 'render', 'post watcher'])
})

// config.compilerOptions is tested in packages/vue since it is only
// supported in the full build.
})
9 changes: 7 additions & 2 deletions packages/runtime-core/src/renderer.ts
Expand Up @@ -2348,6 +2348,7 @@ function baseCreateRenderer(
return hostNextSibling((vnode.anchor || vnode.el)!)
}

let isFlushing = false
const render: RootRenderFunction = (vnode, container, namespace) => {
if (vnode == null) {
if (container._vnode) {
Expand All @@ -2364,8 +2365,12 @@ function baseCreateRenderer(
namespace,
)
}
flushPreFlushCbs()
flushPostFlushCbs()
if (!isFlushing) {
isFlushing = true
flushPreFlushCbs()
flushPostFlushCbs()
isFlushing = false
}
container._vnode = vnode
}

Expand Down

0 comments on commit 3c3561e

Please sign in to comment.