-
Notifications
You must be signed in to change notification settings - Fork 142
[css-properties-values-api] Syntax-checking in CSSStyleDeclaration.setProperty #778
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
Comments
The same goes for Typed OM, registering a property should have no effect on declared/inline style, but for computedStyleMap, getters return typed values after registering. |
.. or maybe not. I guess it's kind of weird if, for a
If typeness and syntax-checking really is a computed-value time thing only, here's how that could look in the spec: andruud@05ba373 |
The behavior is inconsistent, but intentional. Registered custom properties don't reject invalid values at parse time from a style sheet, so that browsers don't have to reparse all the styles on the page to determine the correct cascade (or, equivalently, preserve the entire list of cascaded values for every custom property); instead, you just decide at computed-value time whether the value that won the cascade is valid or not. But there's no similar implementation difficulty for checking the validity of a style set from JS. Throwing an error gives useful feedback to the author, even if it does mean that there's now an order-dependence in the results. (That is, setting a property then registering it gives no error, even if the value doesn't match the grammar; it just ends up as invalid at computed-value time. But registering the property and then setting it will throw an error if it doesn't match the grammar.) I'll amend the note to make it clearer that this is an intentional inconsistency, however. |
Gotcha. Thanks for that explanation. The only thing I don't like about this, is that if a value is set with typed OM:
And we reference that value somewhere:
Then we need to create a "synthetic" token stream for But I guess this is no worse than substituting an interpolated value. 🙂 |
In the current implementation of css-properties-values-api/cssom in Blink, it is not allowed to set a registered custom property to an invalid value using setProperty. The value is just discarded.
Should setProperty still discard invalid values for registered custom properties?
Example:
This was allegedly [1] the agreed-upon behavior at some point, but as of 8dfc2d9 , this behavior seems inconsistent. I think it's more in line with the new spec wording to let setProperty ignore whether the property is registered or not, and do syntax-checking computed-value time.
[1] https://codereview.chromium.org/2607403002
The text was updated successfully, but these errors were encountered: