Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Feb 8, 2025
1 parent 52c120c commit 93eafa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ describe('renderer: component', () => {
).toHaveBeenWarned()
})

test('should not update child component without changes', async () => {
test('should not update child component if style is not changed', async () => {
const text = ref(0)
const spy = vi.fn()

Expand Down
18 changes: 16 additions & 2 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PatchFlags,
ShapeFlags,
isModelListener,
isObject,
isOn,
looseEqual,
} from '@vue/shared'
Expand Down Expand Up @@ -405,7 +406,7 @@ export function shouldUpdateComponent(
for (let i = 0; i < dynamicProps.length; i++) {
const key = dynamicProps[i]
if (
!looseEqual(nextProps![key], prevProps![key]) &&
hasPropValueChanged(nextProps!, prevProps!, key) &&
!isEmitListener(emits, key)
) {
return true
Expand Down Expand Up @@ -447,7 +448,7 @@ function hasPropsChanged(
for (let i = 0; i < nextKeys.length; i++) {
const key = nextKeys[i]
if (
!looseEqual(nextProps[key], prevProps[key]) &&
hasPropValueChanged(nextProps, prevProps, key) &&
!isEmitListener(emitsOptions, key)
) {
return true
Expand All @@ -456,6 +457,19 @@ function hasPropsChanged(
return false
}

function hasPropValueChanged(
nextProps: Data,
prevProps: Data,
key: string,
): boolean {
const nextProp = nextProps[key]
const prevProp = prevProps[key]
if (key === 'style' && isObject(nextProp) && isObject(prevProp)) {
return !looseEqual(nextProp, prevProp)
}
return nextProp !== prevProp
}

export function updateHOCHostEl(
{ vnode, parent }: ComponentInternalInstance,
el: typeof vnode.el, // HostNode
Expand Down

0 comments on commit 93eafa2

Please sign in to comment.