Skip to content

Commit 2121c32

Browse files
committed
fix(runtime-core): fix kebab-case prop required warning
fix #3495 ref #3363
1 parent 37c1709 commit 2121c32

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,25 @@ describe('component props', () => {
319319
expect(`Missing required prop: "num"`).toHaveBeenWarned()
320320
})
321321

322+
// #3495
323+
test('should not warn required props using kebab-case', async () => {
324+
const Comp = {
325+
props: {
326+
fooBar: { type: String, required: true }
327+
},
328+
setup() {
329+
return () => null
330+
}
331+
}
332+
render(
333+
h(Comp, {
334+
'foo-bar': 'hello'
335+
}),
336+
nodeOps.createElement('div')
337+
)
338+
expect(`Missing required prop: "fooBar"`).not.toHaveBeenWarned()
339+
})
340+
322341
test('merging props from mixins and extends', () => {
323342
let setupProps: any
324343
let renderProxy: any

packages/runtime-core/src/componentProps.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,12 @@ function validateProps(
480480
for (const key in options) {
481481
let opt = options[key]
482482
if (opt == null) continue
483-
validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key))
483+
validateProp(
484+
key,
485+
resolvedValues[key],
486+
opt,
487+
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key))
488+
)
484489
}
485490
}
486491

0 commit comments

Comments
 (0)