Skip to content

Commit

Permalink
fix(runtime-core): ensure unmount dynamic components in optimized mode (
Browse files Browse the repository at this point in the history
#11171)

close #11168
  • Loading branch information
jh-leong authored Jun 22, 2024
1 parent 8ae4c29 commit 220fe24
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,32 @@ describe('renderer: optimized mode', () => {
expect(spy).toHaveBeenCalledTimes(1)
})

test('should call onUnmounted hook for dynamic components receiving an existing vnode w/ component children', async () => {
const spy = vi.fn()
const show = ref(1)
const Child = {
setup() {
onUnmounted(spy)
return () => 'child'
},
}
const foo = h('div', null, h(Child))
const app = createApp({
render() {
return show.value
? (openBlock(),
createBlock('div', null, [(openBlock(), createBlock(foo))]))
: createCommentVNode('v-if', true)
},
})

app.mount(root)
show.value = 0
await nextTick()

expect(spy).toHaveBeenCalledTimes(1)
})

// #2444
// `KEYED_FRAGMENT` and `UNKEYED_FRAGMENT` always need to diff its children
test('non-stable Fragment always need to diff its children', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,11 @@ function baseCreateRenderer(
dirs,
memoIndex,
} = vnode

if (patchFlag === PatchFlags.BAIL) {
optimized = false
}

// unset ref
if (ref != null) {
setRef(ref, null, parentSuspense, vnode, true)
Expand Down

0 comments on commit 220fe24

Please sign in to comment.