fix(compiler-core): should not generate CLASS/STYLE patch flags on components
ref #677
This commit is contained in:
		
							parent
							
								
									cda50ea788
								
							
						
					
					
						commit
						a6e2b1052a
					
				@ -739,6 +739,15 @@ describe('compiler: element transform', () => {
 | 
				
			|||||||
      expect(node.dynamicProps).toBe(`["foo", "baz"]`)
 | 
					      expect(node.dynamicProps).toBe(`["foo", "baz"]`)
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // should treat `class` and `style` as PROPS
 | 
				
			||||||
 | 
					    test('PROPS on component', () => {
 | 
				
			||||||
 | 
					      const { node } = parseWithBind(
 | 
				
			||||||
 | 
					        `<Foo :id="foo" :class="cls" :style="styl" />`
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      expect(node.patchFlag).toBe(genFlagText(PatchFlags.PROPS))
 | 
				
			||||||
 | 
					      expect(node.dynamicProps).toBe(`["id", "class", "style"]`)
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    test('FULL_PROPS (v-bind)', () => {
 | 
					    test('FULL_PROPS (v-bind)', () => {
 | 
				
			||||||
      const { node } = parseWithBind(`<div v-bind="foo" />`)
 | 
					      const { node } = parseWithBind(`<div v-bind="foo" />`)
 | 
				
			||||||
      expect(node.patchFlag).toBe(genFlagText(PatchFlags.FULL_PROPS))
 | 
					      expect(node.patchFlag).toBe(genFlagText(PatchFlags.FULL_PROPS))
 | 
				
			||||||
 | 
				
			|||||||
@ -289,9 +289,9 @@ export function buildProps(
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      if (name === 'ref') {
 | 
					      if (name === 'ref') {
 | 
				
			||||||
        hasRef = true
 | 
					        hasRef = true
 | 
				
			||||||
      } else if (name === 'class') {
 | 
					      } else if (name === 'class' && !isComponent) {
 | 
				
			||||||
        hasClassBinding = true
 | 
					        hasClassBinding = true
 | 
				
			||||||
      } else if (name === 'style') {
 | 
					      } else if (name === 'style' && !isComponent) {
 | 
				
			||||||
        hasStyleBinding = true
 | 
					        hasStyleBinding = true
 | 
				
			||||||
      } else if (name !== 'key' && !dynamicPropNames.includes(name)) {
 | 
					      } else if (name !== 'key' && !dynamicPropNames.includes(name)) {
 | 
				
			||||||
        dynamicPropNames.push(name)
 | 
					        dynamicPropNames.push(name)
 | 
				
			||||||
 | 
				
			|||||||
@ -236,20 +236,12 @@ export function shouldUpdateComponent(
 | 
				
			|||||||
    if (patchFlag & PatchFlags.FULL_PROPS) {
 | 
					    if (patchFlag & PatchFlags.FULL_PROPS) {
 | 
				
			||||||
      // presence of this flag indicates props are always non-null
 | 
					      // presence of this flag indicates props are always non-null
 | 
				
			||||||
      return hasPropsChanged(prevProps!, nextProps!)
 | 
					      return hasPropsChanged(prevProps!, nextProps!)
 | 
				
			||||||
    } else {
 | 
					    } else if (patchFlag & PatchFlags.PROPS) {
 | 
				
			||||||
      if (patchFlag & PatchFlags.CLASS) {
 | 
					      const dynamicProps = nextVNode.dynamicProps!
 | 
				
			||||||
        return prevProps!.class !== nextProps!.class
 | 
					      for (let i = 0; i < dynamicProps.length; i++) {
 | 
				
			||||||
      }
 | 
					        const key = dynamicProps[i]
 | 
				
			||||||
      if (patchFlag & PatchFlags.STYLE) {
 | 
					        if (nextProps![key] !== prevProps![key]) {
 | 
				
			||||||
        return hasPropsChanged(prevProps!.style, nextProps!.style)
 | 
					          return true
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (patchFlag & PatchFlags.PROPS) {
 | 
					 | 
				
			||||||
        const dynamicProps = nextVNode.dynamicProps!
 | 
					 | 
				
			||||||
        for (let i = 0; i < dynamicProps.length; i++) {
 | 
					 | 
				
			||||||
          const key = dynamicProps[i]
 | 
					 | 
				
			||||||
          if (nextProps![key] !== prevProps![key]) {
 | 
					 | 
				
			||||||
            return true
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user