diff --git a/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts b/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts index ef5bdbe0136..556ab75209b 100644 --- a/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts +++ b/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts @@ -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', () => { diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index ccb89085c40..66e6965505e 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -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)