Skip to content

Commit

Permalink
fix(compiler-core): should not generate CLASS/STYLE patch flags on co…
Browse files Browse the repository at this point in the history
…mponents

ref #677
  • Loading branch information
yyx990803 committed Apr 10, 2020
1 parent cda50ea commit a6e2b10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,15 @@ describe('compiler: element transform', () => {
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)', () => {
const { node } = parseWithBind(`<div v-bind="foo" />`)
expect(node.patchFlag).toBe(genFlagText(PatchFlags.FULL_PROPS))
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ export function buildProps(
}
if (name === 'ref') {
hasRef = true
} else if (name === 'class') {
} else if (name === 'class' && !isComponent) {
hasClassBinding = true
} else if (name === 'style') {
} else if (name === 'style' && !isComponent) {
hasStyleBinding = true
} else if (name !== 'key' && !dynamicPropNames.includes(name)) {
dynamicPropNames.push(name)
Expand Down
20 changes: 6 additions & 14 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,12 @@ export function shouldUpdateComponent(
if (patchFlag & PatchFlags.FULL_PROPS) {
// presence of this flag indicates props are always non-null
return hasPropsChanged(prevProps!, nextProps!)
} else {
if (patchFlag & PatchFlags.CLASS) {
return prevProps!.class !== nextProps!.class
}
if (patchFlag & PatchFlags.STYLE) {
return hasPropsChanged(prevProps!.style, nextProps!.style)
}
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
}
} else 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
}
}
}
Expand Down

0 comments on commit a6e2b10

Please sign in to comment.