Skip to content

Commit a6e2b10

Browse files
committed
fix(compiler-core): should not generate CLASS/STYLE patch flags on components
ref #677
1 parent cda50ea commit a6e2b10

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

packages/compiler-core/__tests__/transforms/transformElement.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,15 @@ describe('compiler: element transform', () => {
739739
expect(node.dynamicProps).toBe(`["foo", "baz"]`)
740740
})
741741

742+
// should treat `class` and `style` as PROPS
743+
test('PROPS on component', () => {
744+
const { node } = parseWithBind(
745+
`<Foo :id="foo" :class="cls" :style="styl" />`
746+
)
747+
expect(node.patchFlag).toBe(genFlagText(PatchFlags.PROPS))
748+
expect(node.dynamicProps).toBe(`["id", "class", "style"]`)
749+
})
750+
742751
test('FULL_PROPS (v-bind)', () => {
743752
const { node } = parseWithBind(`<div v-bind="foo" />`)
744753
expect(node.patchFlag).toBe(genFlagText(PatchFlags.FULL_PROPS))

packages/compiler-core/src/transforms/transformElement.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ export function buildProps(
289289
}
290290
if (name === 'ref') {
291291
hasRef = true
292-
} else if (name === 'class') {
292+
} else if (name === 'class' && !isComponent) {
293293
hasClassBinding = true
294-
} else if (name === 'style') {
294+
} else if (name === 'style' && !isComponent) {
295295
hasStyleBinding = true
296296
} else if (name !== 'key' && !dynamicPropNames.includes(name)) {
297297
dynamicPropNames.push(name)

packages/runtime-core/src/componentRenderUtils.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,12 @@ export function shouldUpdateComponent(
236236
if (patchFlag & PatchFlags.FULL_PROPS) {
237237
// presence of this flag indicates props are always non-null
238238
return hasPropsChanged(prevProps!, nextProps!)
239-
} else {
240-
if (patchFlag & PatchFlags.CLASS) {
241-
return prevProps!.class !== nextProps!.class
242-
}
243-
if (patchFlag & PatchFlags.STYLE) {
244-
return hasPropsChanged(prevProps!.style, nextProps!.style)
245-
}
246-
if (patchFlag & PatchFlags.PROPS) {
247-
const dynamicProps = nextVNode.dynamicProps!
248-
for (let i = 0; i < dynamicProps.length; i++) {
249-
const key = dynamicProps[i]
250-
if (nextProps![key] !== prevProps![key]) {
251-
return true
252-
}
239+
} else if (patchFlag & PatchFlags.PROPS) {
240+
const dynamicProps = nextVNode.dynamicProps!
241+
for (let i = 0; i < dynamicProps.length; i++) {
242+
const key = dynamicProps[i]
243+
if (nextProps![key] !== prevProps![key]) {
244+
return true
253245
}
254246
}
255247
}

0 commit comments

Comments
 (0)