Open Bug 2087977 Opened 15 days ago Updated 13 days ago

No color swatches for var()/attr() getting the custom property/attribute name from another var() call

Categories

(DevTools :: Inspector: Rules, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: nchevobbe, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Attached file test_case.html —

Steps to reproduce

  1. Open the attached test case
  2. Inspect the "Hello" element

Expected results

In the Rules view h1 rule, for color and background-color, I'm seeing color swatch resp. before attr (lime) and var (blue)

Actual results

No color swatches are displayed

The two declarations fail for related but separate reasons in output-parser.js.

var(var(--y)): #onCloseParenthesisForVar takes the custom property name from the first Ident part (output-parser.js). By the time the outer var() closes, the inner var(--y) has already been reduced to one aggregated part (AGGREGATED_TOKEN_TYPE, with data.substitutedText === "--z"). So no name is found and the handler returns early, before it computes substitutedText and the color swatch (#1907-1934). The generic color branch in #onCloseParenthesis is an else if that never runs for var (#580).

Fix: in the name loop, if the first non-whitespace part before the comma is an aggregated var() part, read the name from token.data.substitutedText. Use it only if it is a string starting with -- once trimmed (an unset inner var gives ""), and keep the nested node as the name node. The rest of the existing path (getVariableData(name), substituted/computed value, swatch) then works unchanged. The fallback handling a few lines below already reads token.data.substitutedText ?? token.data.text from aggregated parts (#1863-1865), so the new code can follow that. Use token?.tokenType in the new code. Expect the jump-to-definition button for --z to sit next to the inner one for --y.

attr(var(--x)): #onCloseParenthesisForAttr has the same "first Ident" assumption and bails (#910-912). But even plain attr(data-color type(<color>)) gets no swatch today: that is bug 2040912, which is not landed and depends on bug 2070443. The type(<color>) here also exists only inside the inner var's substituted text, so it would have to be re-tokenized rather than found through attrTypeIndex. This half should land after bug 2040912 or together with it. The var() half can land on its own.

Tests: add nested cases to testParseVariable/testParseColorVariable in browser_outputparser.js, and a Rules view check in browser_rules_colorpicker-works-with-css-vars.js. For the attr half, extend browser_rules_attr.js.

Suggested severity: S4. A missing color swatch for a CSS syntax that only just shipped (bug 2080511) is cosmetic; the declaration still shows and the variable tooltip still gives the value.


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
If you want to categorize your feedback you can add one of the following tags: ai-triage-{wrong-file, wrong-cause, hallucination, out-of-scope, not-a-bug, wrong-fix, shallow-fix, wrong-severity}.

Needinfo hackbot@mozilla.tld to have a patch generated for this bug, include any questions or directions as needed in your comment.

Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: