fix(runtime-core): avoid manual slot invocation in template expressions interfering with block tracking

fix #1745
This commit is contained in:
Evan You
2020-08-06 10:16:13 -04:00
parent 233d191d0d
commit 791eff3dfb
4 changed files with 62 additions and 19 deletions

View File

@@ -1,5 +1,13 @@
import { renderSlot } from '../../src/helpers/renderSlot'
import { h } from '../../src/h'
import {
h,
withCtx,
createVNode,
openBlock,
createBlock,
Fragment
} from '../../src'
import { PatchFlags } from '@vue/shared/src'
describe('renderSlot', () => {
it('should render slot', () => {
@@ -20,4 +28,23 @@ describe('renderSlot', () => {
renderSlot({ default: (_a, _b, _c) => [h('child')] }, 'default')
expect('SSR-optimized slot function detected').toHaveBeenWarned()
})
// #1745
it('should force enable tracking', () => {
const slot = withCtx(
() => {
return [createVNode('div', null, 'foo', PatchFlags.TEXT)]
},
// mock instance
{} as any
)
// manual invocation should not track
const manual = (openBlock(), createBlock(Fragment, null, slot()))
expect(manual.dynamicChildren!.length).toBe(0)
// renderSlot should track
const templateRendered = renderSlot({ default: slot }, 'default')
expect(templateRendered.dynamicChildren!.length).toBe(1)
})
})