Skip to content

Commit

Permalink
fix(runtime-core): ensure props definition objects are not mutated du…
Browse files Browse the repository at this point in the history
…ring props normalization (close: #6915) (#6916)
  • Loading branch information
LinusBorg committed Oct 22, 2022
1 parent e6224f4 commit 54b6ba3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Expand Up @@ -595,4 +595,23 @@ describe('component props', () => {
JSON.stringify(attrs) + Object.keys(attrs)
)
})

// #691ef
test('should not mutate original props long-form definition object', () => {
const props = {
msg: {
type: String
}
}
const Comp = defineComponent({
props,
render() {}
})

const root = nodeOps.createElement('div')

render(h(Comp, { msg: 'test' }), root)

expect(Object.keys(props.msg).length).toBe(1)
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentProps.ts
Expand Up @@ -522,7 +522,7 @@ export function normalizePropsOptions(
if (validatePropName(normalizedKey)) {
const opt = raw[key]
const prop: NormalizedProp = (normalized[normalizedKey] =
isArray(opt) || isFunction(opt) ? { type: opt } : opt)
isArray(opt) || isFunction(opt) ? { type: opt } : { ...opt })
if (prop) {
const booleanIndex = getTypeIndex(Boolean, prop.type)
const stringIndex = getTypeIndex(String, prop.type)
Expand Down

0 comments on commit 54b6ba3

Please sign in to comment.