Skip to content

Commit dcb3841

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Fix custom property value computation for the diamond pattern
Previously, cycle detection for custom property value compuation to diamond patterns wrong, which looks like this: --root: var(--a) var(--b); --a: var(--sink); --b: var(--sink); --sink: 0px; We detected there was no cycle, but having visited --sink before we would fall back to the fallback instead of using the previously computed value. Fixed: 364687927 Change-Id: I296935ca24a491ff8c03aa39660bd844940a7ce5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5975686 Commit-Queue: Philip Pfaffe <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Auto-Submit: Philip Pfaffe <[email protected]>
1 parent ce8c220 commit dcb3841

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

front_end/core/sdk/CSSMatchedStyles.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ describe('CSSMatchedStyles', () => {
6060
ruleMatch(
6161
'div',
6262
[
63+
{name: '--diamond', value: 'var(--diamond-a) var(--diamond-b)'},
64+
{name: '--diamond-a', value: 'var(--foo)'},
65+
{name: '--diamond-b', value: 'var(--foo)'},
6366
{name: '--foo', value: 'active-foo'},
6467
{name: '--baz', value: 'active-baz !important', important: true},
6568
{name: '--baz', value: 'passive-baz'},
@@ -106,6 +109,7 @@ describe('CSSMatchedStyles', () => {
106109
await testCssValueEquals('--theme', 'darkgrey');
107110
await testCssValueEquals('--shadow', '1px darkgrey');
108111
await testCssValueEquals('--width', '1px');
112+
await testCssValueEquals('--diamond', 'active-foo active-foo');
109113
});
110114

111115
it('correctly resolves the declaration', async () => {

front_end/core/sdk/CSSMatchedStyles.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,16 +1112,19 @@ class DOMInheritanceCascade {
11121112
record.updateRoot(childRecord);
11131113
return null;
11141114
}
1115-
} else {
1116-
const cssVariableValue = this.innerComputeCSSVariable(nodeCascade, match.name, sccRecord);
1117-
// Variable reference is resolved, so return it.
1118-
const childRecord = sccRecord.get(nodeCascade, match.name);
1119-
// The SCC record for the referenced variable may not exist if the var was already computed in a previous
1120-
// iteration. That means it's in a different SCC.
1121-
childRecord && record.updateRoot(childRecord);
1122-
if (cssVariableValue?.value) {
1123-
return cssVariableValue?.value;
1124-
}
1115+
1116+
// We've seen the variable before, so we can look up the text directly.
1117+
return this.#computedCSSVariables.get(nodeCascade)?.get(match.name)?.value ?? null;
1118+
}
1119+
1120+
const cssVariableValue = this.innerComputeCSSVariable(nodeCascade, match.name, sccRecord);
1121+
// Variable reference is resolved, so return it.
1122+
const newChildRecord = sccRecord.get(nodeCascade, match.name);
1123+
// The SCC record for the referenced variable may not exist if the var was already computed in a previous
1124+
// iteration. That means it's in a different SCC.
1125+
newChildRecord && record.updateRoot(newChildRecord);
1126+
if (cssVariableValue?.value) {
1127+
return cssVariableValue?.value;
11251128
}
11261129

11271130
// Variable reference is not resolved, use the fallback.

0 commit comments

Comments
 (0)