-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-values-5] Maybe min, max and step should not be part of the random-caching-key #11742
Comments
The issue is that if min/max/step aren't included, then it exposes details of exactly how you generate the random value. To avoid that, I'd have to specify that the random value is, specifically, a 0-1 real, and then specify exactly how it's turned into the random value. (aka, scaled to the desired range, or converted to a 0-N integer for the step) I definitely could do that, and it would avoid some other oddities (like |
I think the more obvious way to do this would be to use the same
You can do the same thing for this: pull out the I think these use cases are relatively rare, and it's more obvious what you're doing if you synchronize the I think what's more likely, actually, is that you want two
But this will generate squares right now, right? It seems to me that requiring a shared name to tie them together makes more sense than requiring different names to differentiate. As you say, if you accidentally end up with two The important thing is to make sure that |
That's how my brain expected it to work. But maybe that's programmer brain. |
See also #11747, which would be resolved in the min/max/step were not part of the random key. |
These arguments are pretty convincing, and being able to knock out #11747 would be nice. However...
The issue with making a "default" random() (without an explicit caching key) assume a unique key is that it's not very clear to authors when such a key would be generated. For example: .rectangle {
/* these would be different random values */
width: random(10px, 100px);
height: random(10px, 100px);
}
.rectangle-2 {
/* these would be different random values */
--size: random(10px, 100px);
width: var(--size);
height: var(--size);
}
@property --size2 { syntax: "<length>"; inherits: true; initial-value: 0px; }
.square {
/* these would be the *same* random value, making squares */
--size2: random(10px, 100px);
width: var(--size);
height: var(--size);
} To an extent authors already have this confusion, since This is how I arrived at the current caching behavior - it can result in accidentally linked random values sometimes, but it also ensures that authors don't have to care about when the substitution occurs. So, hm, tradeoffs either way. Maybe it is better to force authors to think about the variable resolution time in return for having "more random" behavior by default and avoiding the value-resolution dependence. |
Ah, right, the other reason I made the current behavior is it reduces the coupling to the precise source document. That is, currently, you can have multiple rules applying the same declaration to an element, and it's the exact same behavior as only having one of them apply. With "implicit unique key", you lose this: having multiple stylesheets applying the same styles to an element will give different results. This exposes things like stylesheet deduping, which currently are undetectable from inside the page. It also exposes the difference between applying a style to multiple elements via a selector and via The current behavior instead makes the caching key based purely on the source text itself, not its location, so you can't tell whether the same value is applied from several rules or just one, or if a repeated stylesheet is duped or deduped, etc. The accidental linking of functions that happen to have the same arguments is just an unfortunate side effect. I included as much data as possible in the key precisely to make this less likely to happen by accident. |
Currently, CSS Values 5 says that the min, max and step are part of the
random-caching-key
.However, this prevents some possibly useful techniques where an element shares the same random value, but with different min, max and step with another property on the same element, or with another element.
Conceptually, I would expect that the underlying 0-1 random number is sampled based only on the
dashed-ident
orper-element
keyword, and then min, max and step are just math applied to that underlying value.Consider
I want this box to have a random size, but always a 2/1 aspect ratio. With the current spec, width and height get their own random values.
Another example might be that you have two elements that want a width based on a single random value, but they quantize that value in different ways.
The text was updated successfully, but these errors were encountered: