Skip to content

Commit 54b6ba3

Browse files
authored
fix(runtime-core): ensure props definition objects are not mutated during props normalization (close: #6915) (#6916)
1 parent e6224f4 commit 54b6ba3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/runtime-core/__tests__/componentProps.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,23 @@ describe('component props', () => {
595595
JSON.stringify(attrs) + Object.keys(attrs)
596596
)
597597
})
598+
599+
// #691ef
600+
test('should not mutate original props long-form definition object', () => {
601+
const props = {
602+
msg: {
603+
type: String
604+
}
605+
}
606+
const Comp = defineComponent({
607+
props,
608+
render() {}
609+
})
610+
611+
const root = nodeOps.createElement('div')
612+
613+
render(h(Comp, { msg: 'test' }), root)
614+
615+
expect(Object.keys(props.msg).length).toBe(1)
616+
})
598617
})

packages/runtime-core/src/componentProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export function normalizePropsOptions(
522522
if (validatePropName(normalizedKey)) {
523523
const opt = raw[key]
524524
const prop: NormalizedProp = (normalized[normalizedKey] =
525-
isArray(opt) || isFunction(opt) ? { type: opt } : opt)
525+
isArray(opt) || isFunction(opt) ? { type: opt } : { ...opt })
526526
if (prop) {
527527
const booleanIndex = getTypeIndex(Boolean, prop.type)
528528
const stringIndex = getTypeIndex(String, prop.type)

0 commit comments

Comments
 (0)