Skip to content

Conversation

soouup
Copy link
Contributor

@soouup soouup commented Jan 16, 2020

Remove the repeat key in v-if when you set key property directly.

Template:

<div>
  <div v-if="xxx" key="2"></div>
</div>

Before:

import { openBlock, createVNode, createBlock, createCommentVNode } from "vue"

export function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    (openBlock(), (_ctx.xxx)
      ? createBlock("div", {
          // this key is redundant
          key: 0,
          key: "2"
        })
      : createCommentVNode("v-if", true))
  ]))
}

After:

import { openBlock, createVNode, createBlock, createCommentVNode } from "vue"

export function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    (openBlock(), (_ctx.xxx)
      ? createBlock("div", { key: "2" })
      : createCommentVNode("v-if", true))
  ]))
}

@yyx990803
Copy link
Member

Can you add a test case for this? Can be in vIf.spec.ts and simply assert the snapshot.

@yyx990803 yyx990803 merged commit aca2c2a into vuejs:master Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants