3.0.0-rc.9, 3.0.0-rc.6, 3.0.0-rc.1
https://codepen.io/FrankFang/pen/jOqweRE?editors=0010
click the button to set "selected" to "tab2"
"content 1" turns to "content 2"
"content 1" stays there
Not completely sure of the usage of slots like that but this also fails:
setup(props, context){
return () => {
const defaults = context.slots.default()
const current = defaults.filter((tag) => {
return tag.props.title === props.selected
})[0]
console.log('tab', current)
return h('div', {}, current)
}
}
Adding a key makes it work:
return h('div', {}, Vue.cloneVNode(current, { key: props.selected }))
Isn't it a bug?
I've updated the demo: https://codepen.io/FrankFang/pen/dyMzOBd?editors=0010
It's a simple tab switcher with a bug.
expected: content changes
fact: content never changes
When using <component :is="vnode"> and passing vnode of the same type, you need to provide keys:
<component :is="current" :key="selected" />
Otherwise, you are passing two compiled vnodes of the same type to the renderer. Because they are compiled as completely static, they will not be updated at all.
Most helpful comment
When using
<component :is="vnode">and passing vnode of the same type, you need to provide keys:Otherwise, you are passing two compiled vnodes of the same type to the renderer. Because they are compiled as completely static, they will not be updated at all.