Skip to content

Commit c5c9bbe

Browse files
committed
fix: 修复仅有class或style变动或仅有style属性无class属性时ComputedStyle不触发变动的Bug
1 parent acb7bf5 commit c5c9bbe

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/uni-app-vue/lib/uvue.runtime.esm.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8774,15 +8774,15 @@ function triggerComputedStyleUpdate(instance) {
87748774
if (interceptor.classAttr !== "class" || interceptor.styleAttr !== "style") {
87758775
return;
87768776
}
8777+
let styles = interceptor.styles;
87778778
if (interceptor.classAttr === "class" && interceptor.classStyles && interceptor.classStylesWeight) {
8778-
interceptor.styles = mergeClassStyles(
8779+
styles = mergeClassStyles(
87798780
interceptor.classStyles,
87808781
interceptor.classStylesWeight,
87818782
interceptor.styles
87828783
);
87838784
}
87848785
const r = interceptor.reactiveComputedStyle;
8785-
const styles = interceptor.styles;
87868786
for (const key in r) {
87878787
const isCSSVar = key.startsWith("--");
87888788
const camelizedKey = isCSSVar ? key : camelize(key);
@@ -9269,7 +9269,7 @@ function parseStyleDecl(prop, value) {
92699269
function isSame(a, b) {
92709270
return isString(a) && isString(b) || typeof a === "number" && typeof b === "number" ? a == b : a === b;
92719271
}
9272-
function patchStyle(el, prev, next) {
9272+
function patchStyle(el, prev, next, instance = null) {
92739273
if (!next) {
92749274
return;
92759275
}
@@ -9310,9 +9310,11 @@ function patchStyle(el, prev, next) {
93109310
}
93119311
setExtraStyle(el, batchedStyles);
93129312
}
9313-
const instance = getRootElementInstance(el);
9314-
if (instance && instance.computedStyleInterceptors) {
9315-
triggerComputedStyleUpdate(instance);
9313+
if (instance && instance.parent != null && instance !== instance.root && el === instance.subTree.el) {
9314+
setRootElementInstance(el, instance);
9315+
if (instance.computedStyleInterceptors) {
9316+
triggerComputedStyleUpdate(instance);
9317+
}
93169318
}
93179319
if (batchedStyles.size == 0) {
93189320
return;
@@ -9333,7 +9335,7 @@ const patchProp = (el, key, prevValue, nextValue, namespace, prevChildren, paren
93339335
if (key === "class") {
93349336
patchClass(el, prevValue, nextValue, hostInstance || parentComponent);
93359337
} else if (key === "style") {
9336-
patchStyle(el, prevValue, nextValue);
9338+
patchStyle(el, prevValue, nextValue, hostInstance || parentComponent);
93379339
} else if (key === "part") {
93389340
patchPart(el, nextValue, parentComponent);
93399341
} else if (isOn(key)) {

0 commit comments

Comments
 (0)