Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vue3): skip patch style for same props #3761

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions driver/js/packages/hippy-vue-next/src/modules/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ import { isNullOrUndefined } from '../util';
// type of style
type Style = string | Record<string, string | string[]> | null | undefined;

function isStyleExisted(
el: HippyElement,
prev: Style,
next: Style,
) {
const isElementNull = !el;
const isPrevAndNextNull = !prev && !next;
const isPrevEqualToNext = JSON.stringify(prev) === JSON.stringify(next);
return isElementNull || isPrevAndNextNull || isPrevEqualToNext;
}

/**
* set the Style property
*
Expand All @@ -43,6 +54,10 @@ export function patchStyle(
const el = rawEl;
const batchedStyles: NeedToTyped = {};

if (isStyleExisted(el, prev, next)) {
// if the previous and next attributes are the same, skip the patch calculation.
return;
}
if (prev && !next) {
// clear style
el.removeStyle();
Expand Down
Loading