diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index 9c85cd8beb6..e28b282d106 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -553,4 +553,21 @@ describe('renderer: teleport', () => { `"
teleported
"`, ) }) + + // 8146 + test(`ensure correct rendering when target is empty`, async () => { + const root = nodeOps.createElement('div') + const App = { + setup() { + return () => h(Teleport, { to: null }, h('div', 'teleported')) + }, + } + render(h(App), root) + await nextTick() + expect(serializeInner(root)).toMatchInlineSnapshot( + `"
teleported
"`, + ) + expect(`Invalid Teleport target: null`).toHaveBeenWarnedTimes(1) + expect(`Invalid Teleport target on mount`).toHaveBeenWarnedTimes(1) + }) }) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 0de0ebf787e..65bee66f4e1 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -139,7 +139,7 @@ export const TeleportImpl = { } } - if (disabled) { + if (disabled || !target) { mount(container, mainAnchor) } else if (target) { mount(target, targetAnchor)