Skip to content

Commit

Permalink
fix(runtime-core): fix attr fallthrough on compiled framgent w/ singl…
Browse files Browse the repository at this point in the history
…e static element + comments
  • Loading branch information
yyx990803 committed Jul 21, 2020
1 parent 6390ddf commit 1af3531
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
18 changes: 11 additions & 7 deletions packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
openBlock,
createBlock,
FunctionalComponent,
createCommentVNode
createCommentVNode,
Fragment
} from '@vue/runtime-dom'
import { mockWarn } from '@vue/shared'

Expand Down Expand Up @@ -573,12 +574,15 @@ describe('attribute fallthrough', () => {
}

const Child = {
setup(props: any) {
return () => [
createCommentVNode('hello'),
h('button'),
createCommentVNode('world')
]
setup() {
return () => (
openBlock(),
createBlock(Fragment, null, [
createCommentVNode('hello'),
h('button'),
createCommentVNode('world')
])
)
}
}

Expand Down
13 changes: 9 additions & 4 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ export function renderComponentRoot(
return result
}

/**
* dev only
*/
const getChildRoot = (
vnode: VNode
): [VNode, ((root: VNode) => void) | undefined] => {
Expand All @@ -231,12 +234,14 @@ const getChildRoot = (
}
const childRoot = children[0]
const index = rawChildren.indexOf(childRoot)
const dynamicIndex = dynamicChildren
? dynamicChildren.indexOf(childRoot)
: null
const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1
const setRoot = (updatedRoot: VNode) => {
rawChildren[index] = updatedRoot
if (dynamicIndex !== null) dynamicChildren[dynamicIndex] = updatedRoot
if (dynamicIndex > -1) {
dynamicChildren[dynamicIndex] = updatedRoot
} else if (dynamicChildren && updatedRoot.patchFlag > 0) {
dynamicChildren.push(updatedRoot)
}
}
return [normalizeVNode(childRoot), setRoot]
}
Expand Down
23 changes: 14 additions & 9 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,20 @@ export function cloneVNode<T, U>(
vnode: VNode<T, U>,
extraProps?: Data & VNodeProps | null
): VNode<T, U> {
const props = extraProps
? vnode.props
? mergeProps(vnode.props, extraProps)
: extend({}, extraProps)
: vnode.props
// This is intentionally NOT using spread or extend to avoid the runtime
// key enumeration cost.
const { props, patchFlag } = vnode
const mergedProps = extraProps
? props
? mergeProps(props, extraProps)
: extend({}, extraProps)
: props
return {
__v_isVNode: true,
__v_skip: true,
type: vnode.type,
props,
key: props && normalizeKey(props),
props: mergedProps,
key: mergedProps && normalizeKey(mergedProps),
ref: extraProps && extraProps.ref ? normalizeRef(extraProps) : vnode.ref,
scopeId: vnode.scopeId,
children: vnode.children,
Expand All @@ -448,10 +449,14 @@ export function cloneVNode<T, U>(
shapeFlag: vnode.shapeFlag,
// if the vnode is cloned with extra props, we can no longer assume its
// existing patch flag to be reliable and need to add the FULL_PROPS flag.
// note: perserve flag for fragments since they use the flag for children
// fast paths only.
patchFlag:
extraProps && vnode.type !== Fragment
? vnode.patchFlag | PatchFlags.FULL_PROPS
: vnode.patchFlag,
? patchFlag === -1 // hoisted node
? PatchFlags.FULL_PROPS
: patchFlag | PatchFlags.FULL_PROPS
: patchFlag,
dynamicProps: vnode.dynamicProps,
dynamicChildren: vnode.dynamicChildren,
appContext: vnode.appContext,
Expand Down

0 comments on commit 1af3531

Please sign in to comment.