Skip to content

Commit

Permalink
fix(runtime-core): should not rewrite ref when fallthrough slot
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jun 15, 2020
1 parent cf2f278 commit f44d7f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 33 additions & 2 deletions packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
openBlock,
createBlock,
FunctionalComponent,
createCommentVNode
createCommentVNode,
VNode,
withCtx
} from '@vue/runtime-dom'
import { mockWarn } from '@vue/shared'

Expand Down Expand Up @@ -573,7 +575,7 @@ describe('attribute fallthrough', () => {
}

const Child = {
setup(props: any) {
setup() {
return () => [
createCommentVNode('hello'),
h('button'),
Expand All @@ -593,4 +595,33 @@ describe('attribute fallthrough', () => {
button.dispatchEvent(new CustomEvent('click'))
expect(click).toHaveBeenCalled()
})

// #1311
it('should not rewrite ref when fallthrough slot', () => {
const value = ref('')
let vnode: VNode
const Parent = {
render: () => {
return h(
Child,
{ class: 'class' },
{
default: withCtx(() => {
return [(vnode = h('div', { ref: value }))]
})
}
)
}
}
const Child = {
render({ $slots }: any) {
return $slots.default()
}
}

const root = document.createElement('div')
document.body.appendChild(root)
render(h(Parent), root)
expect(vnode!.ref![0].type).toBe(Parent)
})
})
2 changes: 2 additions & 0 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export function renderComponentRoot(
root.shapeFlag & ShapeFlags.ELEMENT ||
root.shapeFlag & ShapeFlags.COMPONENT
) {
const ref = root.ref
root = cloneVNode(root, fallthroughAttrs)
root.ref = ref
} else if (__DEV__ && !accessedAttrs && root.type !== Comment) {
const allAttrs = Object.keys(attrs)
const eventAttrs: string[] = []
Expand Down

0 comments on commit f44d7f0

Please sign in to comment.