From d4cc7b2496f9ed21ef6cac426697eac058da76bb Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 20 Aug 2020 10:43:57 -0400 Subject: [PATCH] fix(teleport): only inherit el for non-patched nodes fix #1903 --- .../runtime-core/__tests__/components/Teleport.spec.ts | 8 ++++---- packages/runtime-core/src/components/Teleport.ts | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index eaa6e227..44a08c66 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -316,7 +316,7 @@ describe('renderer: teleport', () => { }, render: compile(` -
teleported
{{ disabled }} +
teleported
{{ disabled }}
root
`) @@ -326,13 +326,13 @@ describe('renderer: teleport', () => { `"
root
"` ) expect(serializeInner(target)).toMatchInlineSnapshot( - `"
teleported
false"` + `"
teleported
false"` ) disabled.value = true await nextTick() expect(serializeInner(root)).toMatchInlineSnapshot( - `"
teleported
true
root
"` + `"
teleported
true
root
"` ) expect(serializeInner(target)).toBe(``) @@ -343,7 +343,7 @@ describe('renderer: teleport', () => { `"
root
"` ) expect(serializeInner(target)).toMatchInlineSnapshot( - `"
teleported
false"` + `"
teleported
false"` ) }) }) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index ca885c3d..1d6a996d 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -146,7 +146,10 @@ export const TeleportImpl = { const oldChildren = n1.children as VNode[] const children = n2.children as VNode[] for (let i = 0; i < children.length; i++) { - children[i].el = oldChildren[i].el + // only inherit for non-patched nodes (i.e. static ones) + if (!children[i].el) { + children[i].el = oldChildren[i].el + } } } } else if (!optimized) {