diff --git a/packages/runtime-core/__tests__/rendererTemplateRef.spec.ts b/packages/runtime-core/__tests__/rendererTemplateRef.spec.ts index a7ae7a06bfd..ae30878a4fc 100644 --- a/packages/runtime-core/__tests__/rendererTemplateRef.spec.ts +++ b/packages/runtime-core/__tests__/rendererTemplateRef.spec.ts @@ -10,6 +10,7 @@ import { render, serializeInner, shallowRef, + watch, } from '@vue/runtime-test' describe('api: template refs', () => { @@ -179,6 +180,51 @@ describe('api: template refs', () => { expect(el.value).toBe(null) }) + // #12639 + it('update and unmount child in the same tick', async () => { + const root = nodeOps.createElement('div') + const el = ref(null) + const toggle = ref(true) + const show = ref(true) + + const Comp = defineComponent({ + emits: ['change'], + props: ['show'], + setup(props, { emit }) { + watch( + () => props.show, + () => { + emit('change') + }, + ) + return () => h('div', 'hi') + }, + }) + + const App = { + setup() { + return { + refKey: el, + } + }, + render() { + return toggle.value + ? h(Comp, { + ref: 'refKey', + show: show.value, + onChange: () => (toggle.value = false), + }) + : null + }, + } + render(h(App), root) + expect(el.value).not.toBe(null) + + show.value = false + await nextTick() + expect(el.value).toBe(null) + }) + test('string ref inside slots', async () => { const root = nodeOps.createElement('div') const spy = vi.fn()