Skip to content

Commit fcb4e25

Browse files
authored
feat: show unresolved inherited values in style panel (#4990)
Per user request we will not show computed value when inherited from ancestor. Chrome devtools seem to show unresolved values in "inherited" section. <img width="252" alt="image" src="https://github.com/user-attachments/assets/b7f22ec5-e2ea-47aa-9bad-80622d0aa5f9" />
1 parent 0169791 commit fcb4e25

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

apps/builder/app/shared/style-object-model.test.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,11 +954,11 @@ test("access cascaded value without resolving", () => {
954954
).toEqual({ type: "keyword", value: "initial" });
955955
});
956956

957-
test("fallback cascaded value to inherited computed value", () => {
957+
test("fallback cascaded value to initial value", () => {
958958
const model = createModel({
959959
css: `
960960
body {
961-
border-top-color: currentcolor;
961+
width: 10px;
962962
}
963963
`,
964964
jsx: (
@@ -971,9 +971,32 @@ test("fallback cascaded value to inherited computed value", () => {
971971
getComputedStyleDecl({
972972
model,
973973
instanceSelector: ["box", "body"],
974-
property: "border-top-color",
974+
property: "width",
975+
}).cascadedValue
976+
).toEqual({ type: "keyword", value: "auto" });
977+
});
978+
979+
test("fallback cascaded value to inherited unresolved value", () => {
980+
const model = createModel({
981+
css: `
982+
body {
983+
--color: red;
984+
color: var(--color);
985+
}
986+
`,
987+
jsx: (
988+
<$.Body ws:id="body" class="body">
989+
<$.Box ws:id="box" class="box"></$.Box>
990+
</$.Body>
991+
),
992+
});
993+
expect(
994+
getComputedStyleDecl({
995+
model,
996+
instanceSelector: ["box", "body"],
997+
property: "color",
975998
}).cascadedValue
976-
).toEqual({ type: "keyword", value: "currentColor" });
999+
).toEqual({ type: "var", value: "color" });
9771000
});
9781001

9791002
test("work with unknown or invalid properties", () => {

apps/builder/app/shared/style-object-model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export const getComputedStyleDecl = ({
342342
state,
343343
property,
344344
});
345+
const inheritedCascadedValue = cascadedValue;
345346
cascadedValue = cascaded?.value;
346347
source = cascaded?.source ?? { name: "default" };
347348

@@ -372,6 +373,7 @@ export const getComputedStyleDecl = ({
372373
// defaulting https://drafts.csswg.org/css-cascade-5/#defaulting
373374
else if (inherited) {
374375
specifiedValue = inheritedValue;
376+
cascadedValue = inheritedCascadedValue;
375377
source = inheritedSource;
376378
} else {
377379
specifiedValue = initialValue;
@@ -436,8 +438,8 @@ export const getComputedStyleDecl = ({
436438
usedValue = currentColor.usedValue;
437439
}
438440

439-
// fallback to inherited value
440-
cascadedValue ??= computedValue;
441+
// fallback to initial value
442+
cascadedValue ??= initialValue;
441443

442444
return { property, source, cascadedValue, computedValue, usedValue };
443445
};

0 commit comments

Comments
 (0)