fix(runtime-core): openBlock() should not be tracked when block tracking is disabled

This commit is contained in:
Evan You 2020-09-02 12:15:36 -04:00
parent 552ad4e926
commit ad93fa42fc
2 changed files with 14 additions and 2 deletions
packages/runtime-core

@ -12,7 +12,7 @@ import {
} from '../src/vnode' } from '../src/vnode'
import { Data } from '../src/component' import { Data } from '../src/component'
import { ShapeFlags, PatchFlags } from '@vue/shared' 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 { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
import { setCurrentRenderingInstance } from '../src/componentRenderUtils' import { setCurrentRenderingInstance } from '../src/componentRenderUtils'
@ -535,6 +535,18 @@ describe('vnode', () => {
expect(vnode.dynamicChildren).toStrictEqual([vnode1]) expect(vnode.dynamicChildren).toStrictEqual([vnode1])
expect(vnode1.dynamicChildren).toStrictEqual([vnode2]) 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', () => { describe('transformVNodeArgs', () => {

@ -235,7 +235,7 @@ export function createBlock(
closeBlock() closeBlock()
// a block is always going to be patched, so track it as a child of its // a block is always going to be patched, so track it as a child of its
// parent block // parent block
if (currentBlock) { if (shouldTrack > 0 && currentBlock) {
currentBlock.push(vnode) currentBlock.push(vnode)
} }
return vnode return vnode