Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): should remove the props with camelCase key #1413

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('component props', () => {
let proxy: any

const Comp = defineComponent({
props: ['fooBar'],
props: ['fooBar', 'barBaz'],
render() {
props = this.$props
attrs = this.$attrs
Expand All @@ -42,13 +42,16 @@ describe('component props', () => {
expect(attrs).toEqual({ bar: 3, baz: 4 })

// test updating kebab-case should not delete it (#955)
render(h(Comp, { 'foo-bar': 3, bar: 3, baz: 4 }), root)
render(h(Comp, { 'foo-bar': 3, bar: 3, baz: 4, barBaz: 5 }), root)
expect(proxy.fooBar).toBe(3)
expect(props).toEqual({ fooBar: 3 })
expect(proxy.barBaz).toBe(5)
expect(props).toEqual({ fooBar: 3,barBaz: 5 })
expect(attrs).toEqual({ bar: 3, baz: 4 })

render(h(Comp, { qux: 5 }), root)
expect(proxy.fooBar).toBeUndefined()
// remove the props with camelCase key (#1412)
expect(proxy.barBaz).toBeUndefined()
expect(props).toEqual({})
expect(attrs).toEqual({ qux: 5 })
})
Expand Down
10 changes: 8 additions & 2 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,19 @@ export function updateProps(
for (const key in rawCurrentProps) {
if (
!rawProps ||
(!hasOwn(rawProps, key) &&
(
// for camelCase
!hasOwn(rawProps, key) &&
// it's possible the original props was passed in as kebab-case
// and converted to camelCase (#955)
((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))
) {
if (options) {
if (rawPrevProps && rawPrevProps[kebabKey!] !== undefined) {
if (rawPrevProps && (
// for camelCase
rawPrevProps[key] !== undefined ||
// for kebab-case
rawPrevProps[kebabKey!] !== undefined)) {
props[key] = resolvePropValue(
options,
rawProps || EMPTY_OBJ,
Expand Down