Skip to content

Fix merging of ref props in addProps #3

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

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 44 additions & 0 deletions src/__tests__/vue-vnode-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Fragment,
h,
isVNode,
ref,
Text,
type VNode,
type VNodeArrayChildren,
Expand Down Expand Up @@ -452,6 +453,49 @@ describe('addProps', () => {
expect(fragment[0]).toBe(spanNode)
expect(spanNode.props).toBe(null)
})

it('addProps - 8259', () => {
let count = 0

const spanRef = ref()
const otherRef = ref()
const spanNode = h('span', { ref: spanRef, class: 'bold', style: 'color: red' })
const startNodes = [spanNode]

const nodes = addProps(startNodes, () => {
count++

return {
ref: otherRef,
class: 'large',
style: 'line-height: 1'
}
})

expect(count).toBe(1)

expect(nodes).toHaveLength(1)

const newNode = nodes[0] as VNode
const props = newNode.props

expect(props?.class).toBe('bold large')
expect(props?.style.color).toBe('red')
expect(props?.style['line-height']).toBe('1')

const mergedRef = newNode.ref

expect(Array.isArray(mergedRef)).toBe(true)
expect(mergedRef).toHaveLength(2)

// Keep TS happy...
if (Array.isArray(mergedRef)) {
const refs = mergedRef.map(({ r }) => r)

expect(refs.includes(spanRef)).toBe(true)
expect(refs.includes(otherRef)).toBe(true)
}
})
})

describe('replaceChildren', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/vue-vnode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const addProps = (
}

if (props && !isEmptyObject(props)) {
return cloneVNode(vnode, props)
return cloneVNode(vnode, props, true)
}
}, options)
}
Expand Down