Skip to content

Commit 1c4e1b6

Browse files
authoredJun 26, 2020
fix(runtime-core): should remove no longer present camelCase props (#1413)
fix #1412
1 parent 056cac9 commit 1c4e1b6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('component props', () => {
2121
let proxy: any
2222

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

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

5051
render(h(Comp, { qux: 5 }), root)
5152
expect(proxy.fooBar).toBeUndefined()
53+
// remove the props with camelCase key (#1412)
54+
expect(proxy.barBaz).toBeUndefined()
5255
expect(props).toEqual({})
5356
expect(attrs).toEqual({ qux: 5 })
5457
})

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,19 @@ export function updateProps(
190190
for (const key in rawCurrentProps) {
191191
if (
192192
!rawProps ||
193-
(!hasOwn(rawProps, key) &&
193+
(
194+
// for camelCase
195+
!hasOwn(rawProps, key) &&
194196
// it's possible the original props was passed in as kebab-case
195197
// and converted to camelCase (#955)
196198
((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))
197199
) {
198200
if (options) {
199-
if (rawPrevProps && rawPrevProps[kebabKey!] !== undefined) {
201+
if (rawPrevProps && (
202+
// for camelCase
203+
rawPrevProps[key] !== undefined ||
204+
// for kebab-case
205+
rawPrevProps[kebabKey!] !== undefined)) {
200206
props[key] = resolvePropValue(
201207
options,
202208
rawProps || EMPTY_OBJ,

0 commit comments

Comments
 (0)
Please sign in to comment.