Skip to content

Commit 77a804b

Browse files
committedFeb 9, 2024
fix(dx): warn against reserved keys as prop name
close #10281
1 parent dfb271a commit 77a804b

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
@@ -729,4 +729,23 @@ describe('component props', () => {
729729

730730
expect(Object.keys(props.msg).length).toBe(1)
731731
})
732+
733+
test('should warn against reserved prop names', () => {
734+
const Comp = defineComponent({
735+
props: {
736+
key: String,
737+
ref: String,
738+
$foo: String,
739+
},
740+
render() {},
741+
})
742+
743+
const root = nodeOps.createElement('div')
744+
745+
render(h(Comp, { msg: 'test' }), root)
746+
747+
expect(`Invalid prop name: "key"`).toHaveBeenWarned()
748+
expect(`Invalid prop name: "ref"`).toHaveBeenWarned()
749+
expect(`Invalid prop name: "$foo"`).toHaveBeenWarned()
750+
})
732751
})

‎packages/runtime-core/src/componentProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ export function normalizePropsOptions(
586586
}
587587

588588
function validatePropName(key: string) {
589-
if (key[0] !== '$') {
589+
if (key[0] !== '$' && !isReservedProp(key)) {
590590
return true
591591
} else if (__DEV__) {
592592
warn(`Invalid prop name: "${key}" is a reserved property.`)

0 commit comments

Comments
 (0)
Please sign in to comment.