From 33d0e907cbec5deaca6b47e6ee4688f02678e8bc Mon Sep 17 00:00:00 2001 From: BeiYuShuiGuoLvDeKongQi <958414905@qq.com> Date: Wed, 12 Aug 2020 00:51:24 +0800 Subject: [PATCH 1/4] fix(runtime-core/Teleport): handle 0 as patchFlag value.(#1813) --- packages/runtime-core/src/components/Teleport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 8c588df128b..30754aa255b 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -139,7 +139,7 @@ export const TeleportImpl = { parentSuspense, isSVG ) - if (n2.patchFlag > 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { + if (n2.patchFlag >= 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { const oldChildren = n1.children as VNode[] const children = n2.children as VNode[] for (let i = 0; i < children.length; i++) { From d63e561fcd92a9b22f56445be08c31817bb637d9 Mon Sep 17 00:00:00 2001 From: BeiYuShuiGuoLvDeKongQi <958414905@qq.com> Date: Wed, 12 Aug 2020 21:30:08 +0800 Subject: [PATCH 2/4] chore(runtime-core/Teleport): add test --- packages/vue/__tests__/index.spec.ts | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/vue/__tests__/index.spec.ts b/packages/vue/__tests__/index.spec.ts index 974fffc0442..7339a0804fa 100644 --- a/packages/vue/__tests__/index.spec.ts +++ b/packages/vue/__tests__/index.spec.ts @@ -208,4 +208,43 @@ describe('compiler + runtime integration', () => { ).toHaveBeenWarned() document.querySelector = origin }) + + // #1813 + it('should not report an error when "0" as patchFlag value', async () => { + const container = document.createElement('div') + const target = document.createElement('div') + const count = ref(0) + const origin = document.querySelector + document.querySelector = jest.fn().mockReturnValue(target) + + const App = { + template: ` + +
+
{{ count }}
+
+
+ `, + data() { + return { + count + } + } + } + createApp(App).mount(container) + expect(container.innerHTML).toBe(``) + expect(target.innerHTML).toBe(`
0
`) + + count.value++ + await nextTick() + expect(container.innerHTML).toBe(``) + expect(target.innerHTML).toBe(`
1
`) + + count.value++ + await nextTick() + expect(container.innerHTML).toBe(``) + expect(target.innerHTML).toBe(``) + + document.querySelector = origin + }) }) From 9126499d47038c4c6523279b331f3f6908fe2664 Mon Sep 17 00:00:00 2001 From: BeiYuShuiGuoLvDeKongQi <958414905@qq.com> Date: Wed, 12 Aug 2020 21:51:17 +0800 Subject: [PATCH 3/4] chore(runtime-core/Teleport): add comment --- packages/runtime-core/src/components/Teleport.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 30754aa255b..24f6e1417c7 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -139,6 +139,8 @@ export const TeleportImpl = { parentSuspense, isSVG ) + // #1813, sometimes when the patchFlag is 0, + // this branch may need to run if (n2.patchFlag >= 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { const oldChildren = n1.children as VNode[] const children = n2.children as VNode[] From d76acf59f430fe24c4055ff1a12cb5fcce1251d9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Aug 2020 17:18:39 -0400 Subject: [PATCH 4/4] Update Teleport.ts --- packages/runtime-core/src/components/Teleport.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 24f6e1417c7..ca885c3d920 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -139,9 +139,10 @@ export const TeleportImpl = { parentSuspense, isSVG ) - // #1813, sometimes when the patchFlag is 0, - // this branch may need to run - if (n2.patchFlag >= 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { + // even in block tree mode we need to make sure all root-level nodes + // in the teleport inherit previous DOM references so that they can + // be moved in future patches. + if (n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { const oldChildren = n1.children as VNode[] const children = n2.children as VNode[] for (let i = 0; i < children.length; i++) {