Skip to content

Commit

Permalink
fix(runtime-core): fix required prop check false positive for kebab-c…
Browse files Browse the repository at this point in the history
…ase edge cases (#12034)

close #12011
  • Loading branch information
yangliguo7 authored Oct 11, 2024
1 parent 10a46f4 commit 9da1ac1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,30 @@ describe('component props', () => {
})
})

//#12011
test('replace camelize with hyphenate to handle props key', () => {
const Comp = {
props: {
hasB4BProp: { type: Boolean, required: true },
},
setup() {
return () => null
},
}
render(
h('div', {}, [
h(Comp, {
'has-b-4-b-prop': true,
}),
h(Comp, {
'has-b4-b-prop': true,
}),
]),
nodeOps.createElement('div'),
)
expect(`Missing required prop: "hasB4BProp"`).not.toHaveBeenWarned()
})

test('warn props mutation', () => {
let instance: ComponentInternalInstance
let setupProps: any
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ function validateProps(
) {
const resolvedValues = toRaw(props)
const options = instance.propsOptions[0]
const camelizePropsKey = Object.keys(rawProps).map(key => camelize(key))
for (const key in options) {
let opt = options[key]
if (opt == null) continue
Expand All @@ -662,7 +663,7 @@ function validateProps(
resolvedValues[key],
opt,
__DEV__ ? shallowReadonly(resolvedValues) : resolvedValues,
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)),
!camelizePropsKey.includes(key),
)
}
}
Expand Down

0 comments on commit 9da1ac1

Please sign in to comment.