From ad93fa42fc8c32d121c0121083d2f0bb40672737 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 2 Sep 2020 12:15:36 -0400 Subject: [PATCH] fix(runtime-core): openBlock() should not be tracked when block tracking is disabled --- packages/runtime-core/__tests__/vnode.spec.ts | 14 +++++++++++++- packages/runtime-core/src/vnode.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index 2ee1872a..0a08d4f3 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -12,7 +12,7 @@ import { } from '../src/vnode' import { Data } from '../src/component' import { ShapeFlags, PatchFlags } from '@vue/shared' -import { h, reactive, isReactive } from '../src' +import { h, reactive, isReactive, setBlockTracking } from '../src' import { createApp, nodeOps, serializeInner } from '@vue/runtime-test' import { setCurrentRenderingInstance } from '../src/componentRenderUtils' @@ -535,6 +535,18 @@ describe('vnode', () => { expect(vnode.dynamicChildren).toStrictEqual([vnode1]) expect(vnode1.dynamicChildren).toStrictEqual([vnode2]) }) + + test('should not track openBlock() when tracking is disabled', () => { + let vnode1 + const vnode = (openBlock(), + createBlock('div', null, [ + setBlockTracking(-1), + (vnode1 = (openBlock(), createBlock('div'))), + setBlockTracking(1), + vnode1 + ])) + expect(vnode.dynamicChildren).toStrictEqual([]) + }) }) describe('transformVNodeArgs', () => { diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index de329ff9..0c468fd0 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -235,7 +235,7 @@ export function createBlock( closeBlock() // a block is always going to be patched, so track it as a child of its // parent block - if (currentBlock) { + if (shouldTrack > 0 && currentBlock) { currentBlock.push(vnode) } return vnode