Open Bug 2090870 Opened 9 days ago Updated 7 days ago

Property-scoped random() in a chained typed attr() is incorrectly shared by every property referencing the attribute

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

People

(Reporter: jwatt, Assigned: jwatt)

References

(Blocks 1 open bug)

Details

When a typed attr() chains to another typed attr() (the attribute's value itself contains attr(... type(...))), the inner attribute value is parsed while custom properties are being resolved in substitute_all, and the result is stored in the attr() part of ComputedSubstitutionFunctions keyed only by the attribute name. If that attribute value contains random(property-scoped, ...) or random(property-index-scoped, ...), the <random-ua-ident> is fixed by whichever property is traversed first, and every other property that references the same attribute gets the same key and therefore the same random value.

This is shown by the following (assuming D340831 has landed, since without it the key is the wrong ua---data-x for everyone, but the sharing is the same):

<div data-y="random(property-scoped, 1px, 300000px)"
     data-x="attr(data-y type(<length>))"
     style="margin-left: attr(data-x type(<length>));
            margin-right: attr(data-x type(<length>));
            padding-left: random(ua-margin-left, 1px, 300000px);
            padding-right: random(ua-margin-right, 1px, 300000px)"></div>

(The padding declarations only exist to show which key won.)

margin-left and margin-right compute to the same value, and both equal padding-right, i.e. both use the key ua-margin-right. Declaring margin-right before margin-left instead makes both equal padding-left. With custom properties (--a: attr(data-x type(<length>)); --b: attr(data-x type(<length>)); margin-left: var(--a); margin-right: var(--b)) both margins get the key ua---b, and with --a plus a longhand margin-right: attr(data-x type(<length>)) both get ua---a.

Depends on: 2087937

I have a branch with a proof-of-concept patch with WPT tests that fixes this by re-parsing the raw attribute and substituting it in a nested replacement context for each property that references it. That works, but it's not the best approach since it re-parses the attribute for every typed attr() that references it, and the nested context would get its own early random() counter once D338646 lands, so property-index-scoped inside a chain would restart at 1. Best to wait until that lands and fix on top of that instead.

The attribute map currently holds the raw parsed attribute value until the traversal in substitute_all overwrites it with the substituted result. We could keep the raw value alongside the resolved one, then when a typed attr() substitutes an attribute whose value contained substitution functions, AttrFunction::replace could re-substitute from the raw value using the current property's replacement context instead of using the cached text. The traversal has already ruled out cycles, so this terminates, and each property gets its own <random-ua-ident>. Using the same context also means the chain shares the property's early random() counter, so property-index-scoped inside a chain continues the property's count (ua-early-margin-1, ua-early-margin-2, ...) rather than restarting at 1 for each substitution.

Note to self: that second part needs its own test.

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