Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): should update parent host el when component self u… #1360

Merged
merged 5 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add test
  • Loading branch information
underfin committed Jun 15, 2020
commit 25a5600ecced3a99fb3cd5709cd088e26fef819b
44 changes: 44 additions & 0 deletions packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
ref,
h,
render,
nodeOps,
serializeInner,
nextTick,
VNode
} from '@vue/runtime-test'

describe('renderer: component', () => {
test('should update parent(hoc) component host el when child component self update', async () => {
const value = ref(true)
let parentVnode: VNode
let childVnode1: VNode
let childVnode2: VNode

const Parent = {
render: () => {
// let Parent first rerender
console.log(value.value)
return (parentVnode = h(Child))
}
}

const Child = {
render: () => {
return value.value
? (childVnode1 = h('div'))
: (childVnode2 = h('span'))
}
}

const root = nodeOps.createElement('div')
render(h(Parent), root)
expect(serializeInner(root)).toBe(`<div></div>`)
expect(parentVnode!.el).toBe(childVnode1!.el)

value.value = false
await nextTick()
expect(serializeInner(root)).toBe(`<span></span>`)
expect(parentVnode!.el).toBe(childVnode2!.el)
})
})
1 change: 1 addition & 0 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ function baseCreateRenderer(
// no update needed. just copy over properties
n2.component = n1.component
n2.el = n1.el
// instance.vnode = n2
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here caused that the vnode isn't euquals to parent.subTree when parent is first rerender

}

Expand Down