Skip to content

Commit

Permalink
fix(runtime-core): stricter compat root mount check
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 28, 2021
1 parent 6690372 commit 32e2133
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
18 changes: 4 additions & 14 deletions packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,10 @@ describe('renderer: component', () => {
})

test('the component VNode should be cloned when reusing it', () => {
const Child = {
setup(props: any, { slots }: SetupContext) {
return () => {
const c = slots.default!()
return [c, c, c]
}
const App = {
render() {
const c = [h(Comp)]
return [c, c, c]
}
}

Expand All @@ -315,14 +313,6 @@ describe('renderer: component', () => {
}
}

const App = {
setup() {
return () => {
return h(Child, () => [h(Comp)])
}
}
}

const root = nodeOps.createElement('div')
render(h(App), root)
expect(serializeInner(root)).toBe(`<h1></h1><h1></h1><h1></h1>`)
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-core/src/compat/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ function installCompatMount(
}
setupComponent(instance)
vnode.component = instance
vnode.isCompatRoot = true

// $mount & $destroy
// these are defined on ctx and picked up by the $mount/$destroy
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,8 @@ function baseCreateRenderer(
) => {
// 2.x compat may pre-creaate the component instance before actually
// mounting
const compatMountInstance = __COMPAT__ && initialVNode.component
const compatMountInstance =
__COMPAT__ && initialVNode.isCompatRoot && initialVNode.component
const instance: ComponentInternalInstance =
compatMountInstance ||
(initialVNode.component = createComponentInstance(
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ export interface VNode<
*/
[ReactiveFlags.SKIP]: true

/**
* @internal __COMPAT__ only
*/
isCompatRoot?: true

type: VNodeTypes
props: (VNodeProps & ExtraProps) | null
key: string | number | null
Expand Down

0 comments on commit 32e2133

Please sign in to comment.