Skip to content

Commit

Permalink
fix(runtime-core): mount children before setting element props
Browse files Browse the repository at this point in the history
fix #1318, close #1320
  • Loading branch information
yyx990803 committed Jun 12, 2020
1 parent aac9b03 commit 8084156
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
31 changes: 17 additions & 14 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,23 @@ function baseCreateRenderer(
isSVG,
props && props.is
)

// mount children first, since some props may rely on child content
// being already rendered, e.g. `<select value>`
if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
hostSetElementText(el, vnode.children as string)
} else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
mountChildren(
vnode.children as VNodeArrayChildren,
el,
null,
parentComponent,
parentSuspense,
isSVG && type !== 'foreignObject',
optimized || !!vnode.dynamicChildren
)
}

// props
if (props) {
for (const key in props) {
Expand Down Expand Up @@ -707,20 +724,6 @@ function baseCreateRenderer(
hostSetScopeId(el, treeOwnerId + '-s')
}

// children
if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
hostSetElementText(el, vnode.children as string)
} else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
mountChildren(
vnode.children as VNodeArrayChildren,
el,
null,
parentComponent,
parentSuspense,
isSVG && type !== 'foreignObject',
optimized || !!vnode.dynamicChildren
)
}
if (transition && !transition.persisted) {
transition.beforeEnter(el)
}
Expand Down
12 changes: 6 additions & 6 deletions packages/runtime-test/__tests__/testRuntime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ describe('test renderer', () => {
})

expect(ops[1]).toEqual({
type: NodeOpTypes.SET_ELEMENT_TEXT,
text: 'hello',
targetNode: root.children[0]
})

expect(ops[2]).toEqual({
type: NodeOpTypes.PATCH,
targetNode: root.children[0],
propKey: 'id',
propPrevValue: null,
propNextValue: 'test'
})

expect(ops[2]).toEqual({
type: NodeOpTypes.SET_ELEMENT_TEXT,
text: 'hello',
targetNode: root.children[0]
})

expect(ops[3]).toEqual({
type: NodeOpTypes.INSERT,
targetNode: root.children[0],
Expand Down

0 comments on commit 8084156

Please sign in to comment.