Skip to content

Commit 9da1ac1

Browse files
authored
fix(runtime-core): fix required prop check false positive for kebab-case edge cases (#12034)
close #12011
1 parent 10a46f4 commit 9da1ac1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,30 @@ describe('component props', () => {
333333
})
334334
})
335335

336+
//#12011
337+
test('replace camelize with hyphenate to handle props key', () => {
338+
const Comp = {
339+
props: {
340+
hasB4BProp: { type: Boolean, required: true },
341+
},
342+
setup() {
343+
return () => null
344+
},
345+
}
346+
render(
347+
h('div', {}, [
348+
h(Comp, {
349+
'has-b-4-b-prop': true,
350+
}),
351+
h(Comp, {
352+
'has-b4-b-prop': true,
353+
}),
354+
]),
355+
nodeOps.createElement('div'),
356+
)
357+
expect(`Missing required prop: "hasB4BProp"`).not.toHaveBeenWarned()
358+
})
359+
336360
test('warn props mutation', () => {
337361
let instance: ComponentInternalInstance
338362
let setupProps: any

packages/runtime-core/src/componentProps.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ function validateProps(
654654
) {
655655
const resolvedValues = toRaw(props)
656656
const options = instance.propsOptions[0]
657+
const camelizePropsKey = Object.keys(rawProps).map(key => camelize(key))
657658
for (const key in options) {
658659
let opt = options[key]
659660
if (opt == null) continue
@@ -662,7 +663,7 @@ function validateProps(
662663
resolvedValues[key],
663664
opt,
664665
__DEV__ ? shallowReadonly(resolvedValues) : resolvedValues,
665-
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)),
666+
!camelizePropsKey.includes(key),
666667
)
667668
}
668669
}

0 commit comments

Comments
 (0)