return function render(_ctx, _cache) {
with (_ctx) {
- const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue
+ const { openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue
return (_openBlock(), _createBlock(\\"div\\", null, [
- _createVNode(\\"div\\", { key: foo })
+ (_openBlock(), _createBlock(\\"div\\", { key: foo }))
]))
}
}"
return function render(_ctx, _cache) {
with (_ctx) {
- const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue
+ const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock } = _Vue
return (_openBlock(true), _createBlock(_Fragment, null, _renderList(items, (item) => {
return (_openBlock(), _createBlock(\\"span\\", { key: item }))
isBlock: true
})
})
+
+ // #938
+ test('element with dynamic keys should be forced into blocks', () => {
+ const ast = parse(`<div><div :key="foo" /></div>`)
+ transform(ast, {
+ nodeTransforms: [transformElement]
+ })
+ expect((ast as any).children[0].children[0].codegenNode).toMatchObject({
+ type: NodeTypes.VNODE_CALL,
+ tag: `"div"`,
+ isBlock: true
+ })
+ })
})
let dynamicPropNames: string[] | undefined
let vnodeDirectives: VNodeCall['directives']
- // <svg> and <foreignObject> must be forced into blocks so that block
- // updates inside get proper isSVG flag at runtime. (#639, #643)
- // This is technically web-specific, but splitting the logic out of core
- // leads to too much unnecessary complexity.
let shouldUseBlock =
- !isComponent && (tag === 'svg' || tag === 'foreignObject')
+ !isComponent &&
+ // <svg> and <foreignObject> must be forced into blocks so that block
+ // updates inside get proper isSVG flag at runtime. (#639, #643)
+ // This is technically web-specific, but splitting the logic out of core
+ // leads to too much unnecessary complexity.
+ (tag === 'svg' ||
+ tag === 'foreignObject' ||
+ // #938: elements with dynamic keys should be forced into blocks
+ findProp(node, 'key', true))
// props
if (props.length > 0) {
vnodePatchFlag,
vnodeDynamicProps,
vnodeDirectives,
- shouldUseBlock,
+ !!shouldUseBlock,
false /* isForBlock */,
node.loc
)