fix(runtime-core): should remove no longer present camelCase props (#1413)
fix #1412
This commit is contained in:
		
							parent
							
								
									056cac9185
								
							
						
					
					
						commit
						1c4e1b6792
					
				@ -21,7 +21,7 @@ describe('component props', () => {
 | 
				
			|||||||
    let proxy: any
 | 
					    let proxy: any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const Comp = defineComponent({
 | 
					    const Comp = defineComponent({
 | 
				
			||||||
      props: ['fooBar'],
 | 
					      props: ['fooBar', 'barBaz'],
 | 
				
			||||||
      render() {
 | 
					      render() {
 | 
				
			||||||
        props = this.$props
 | 
					        props = this.$props
 | 
				
			||||||
        attrs = this.$attrs
 | 
					        attrs = this.$attrs
 | 
				
			||||||
@ -42,13 +42,16 @@ describe('component props', () => {
 | 
				
			|||||||
    expect(attrs).toEqual({ bar: 3, baz: 4 })
 | 
					    expect(attrs).toEqual({ bar: 3, baz: 4 })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // test updating kebab-case should not delete it (#955)
 | 
					    // 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(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 })
 | 
					    expect(attrs).toEqual({ bar: 3, baz: 4 })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    render(h(Comp, { qux: 5 }), root)
 | 
					    render(h(Comp, { qux: 5 }), root)
 | 
				
			||||||
    expect(proxy.fooBar).toBeUndefined()
 | 
					    expect(proxy.fooBar).toBeUndefined()
 | 
				
			||||||
 | 
					    // remove the props with camelCase key (#1412)
 | 
				
			||||||
 | 
					    expect(proxy.barBaz).toBeUndefined()
 | 
				
			||||||
    expect(props).toEqual({})
 | 
					    expect(props).toEqual({})
 | 
				
			||||||
    expect(attrs).toEqual({ qux: 5 })
 | 
					    expect(attrs).toEqual({ qux: 5 })
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
				
			|||||||
@ -190,13 +190,19 @@ export function updateProps(
 | 
				
			|||||||
    for (const key in rawCurrentProps) {
 | 
					    for (const key in rawCurrentProps) {
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        !rawProps ||
 | 
					        !rawProps ||
 | 
				
			||||||
        (!hasOwn(rawProps, key) &&
 | 
					        (
 | 
				
			||||||
 | 
					          // for camelCase
 | 
				
			||||||
 | 
					          !hasOwn(rawProps, key) &&
 | 
				
			||||||
          // it's possible the original props was passed in as kebab-case
 | 
					          // it's possible the original props was passed in as kebab-case
 | 
				
			||||||
          // and converted to camelCase (#955)
 | 
					          // and converted to camelCase (#955)
 | 
				
			||||||
          ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))
 | 
					          ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        if (options) {
 | 
					        if (options) {
 | 
				
			||||||
          if (rawPrevProps && rawPrevProps[kebabKey!] !== undefined) {
 | 
					          if (rawPrevProps && (
 | 
				
			||||||
 | 
					            // for camelCase
 | 
				
			||||||
 | 
					            rawPrevProps[key] !== undefined ||
 | 
				
			||||||
 | 
					            // for kebab-case
 | 
				
			||||||
 | 
					            rawPrevProps[kebabKey!] !== undefined)) {
 | 
				
			||||||
            props[key] = resolvePropValue(
 | 
					            props[key] = resolvePropValue(
 | 
				
			||||||
              options,
 | 
					              options,
 | 
				
			||||||
              rawProps || EMPTY_OBJ,
 | 
					              rawProps || EMPTY_OBJ,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user