Skip to content

Commit 5e50eb9

Browse files
committed
fix: use cloneVNode when altering props in render functions
Resolves #252 https://vuejs.org/api/render-function.html#clonevnode
1 parent af65683 commit 5e50eb9

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

src/runtime/components/elements/AvatarGroup.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, computed, defineComponent } from 'vue'
1+
import { h, cloneVNode, computed, defineComponent } from 'vue'
22
import type { PropType } from 'vue'
33
import { defu } from 'defu'
44
import { classNames, getSlotsChildren } from '../../utils'
@@ -39,18 +39,20 @@ export default defineComponent({
3939
const max = computed(() => typeof props.max === 'string' ? parseInt(props.max, 10) : props.max)
4040

4141
const clones = computed(() => children.value.map((node, index) => {
42+
const vProps: any = {}
43+
4244
if (!props.max || (max.value && index < max.value)) {
4345
if (props.size) {
44-
node.props.size = props.size
46+
vProps.size = props.size
4547
}
4648

47-
node.props.class = node.props.class || ''
48-
node.props.class += ` ${classNames(
49+
vProps.class = node.props.class || ''
50+
vProps.class += ` ${classNames(
4951
ui.value.ring,
5052
ui.value.margin
5153
)}`
5254

53-
return node
55+
return cloneVNode(node, vProps)
5456
}
5557

5658
if (max.value !== undefined && index === max.value) {

src/runtime/components/elements/ButtonGroup.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, computed, defineComponent } from 'vue'
1+
import { h, cloneVNode, computed, defineComponent } from 'vue'
22
import type { PropType } from 'vue'
33
import { defu } from 'defu'
44
import { getSlotsChildren } from '../../utils'
@@ -44,28 +44,30 @@ export default defineComponent({
4444
}[ui.value.rounded]))
4545

4646
const clones = computed(() => children.value.map((node, index) => {
47+
const vProps: any = {}
48+
4749
if (props.size) {
48-
node.props.size = props.size
50+
vProps.size = props.size
4951
}
5052

51-
node.props.class = node.props.class || ''
52-
node.props.class += ' !shadow-none'
53-
node.props.ui = node.props.ui || {}
54-
node.props.ui.rounded = ''
53+
vProps.class = node.props.class || ''
54+
vProps.class += ' !shadow-none'
55+
vProps.ui = node.props.ui || {}
56+
vProps.ui.rounded = ''
5557

5658
if (index === 0) {
57-
node.props.ui.rounded = rounded.value.left
59+
vProps.ui.rounded = rounded.value.left
5860
}
5961

6062
if (index > 0) {
61-
node.props.class += ' -ml-px'
63+
vProps.class += ' -ml-px'
6264
}
6365

6466
if (index === children.value.length - 1) {
65-
node.props.ui.rounded = rounded.value.right
67+
vProps.ui.rounded = rounded.value.right
6668
}
6769

68-
return node
70+
return cloneVNode(node, vProps)
6971
}))
7072

7173
return () => h('div', { class: [ui.value.wrapper, ui.value.rounded, ui.value.shadow] }, clones.value)

src/runtime/components/forms/FormGroup.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, computed, defineComponent } from 'vue'
1+
import { h, cloneVNode, computed, defineComponent } from 'vue'
22
import type { PropType } from 'vue'
33
import { defu } from 'defu'
44
import { getSlotsChildren } from '../../utils'
@@ -53,18 +53,20 @@ export default defineComponent({
5353
const children = computed(() => getSlotsChildren(slots))
5454

5555
const clones = computed(() => children.value.map((node) => {
56+
const vProps: any = {}
57+
5658
if (props.error) {
57-
node.props.oldColor = node.props.color
58-
node.props.color = 'red'
59+
vProps.oldColor = node.props.color
60+
vProps.color = 'red'
5961
} else {
60-
node.props.color = node.props.oldColor
62+
vProps.color = vProps.oldColor
6163
}
6264

6365
if (props.name) {
64-
node.props.name = props.name
66+
vProps.name = props.name
6567
}
6668

67-
return node
69+
return cloneVNode(node, vProps)
6870
}))
6971

7072
return () => h('div', { class: [ui.value.wrapper] }, [

0 commit comments

Comments
 (0)