Skip to content
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-properties-values-api-1] CSSPropertyRule.initialValue should not be nullable #1115

Open
cdoublev opened this issue Nov 8, 2023 · 1 comment

Comments

@cdoublev
Copy link
Contributor

cdoublev commented Nov 8, 2023

The spec says it is nullable / it may not be present:

initialValue, of type CSSOMString, readonly, nullable

The initial value associated with the @property rule, which may not be present.

https://drafts.css-houdini.org/css-properties-values-api-1/#dom-csspropertyrule-initialvalue

But also:

If the value of the syntax descriptor is the universal syntax definition, then the initial-value descriptor is optional. If omitted, the initial value of the property is the guaranteed-invalid value.

Otherwise, [...] The initial-value descriptor must be present.

https://drafts.css-houdini.org/css-properties-values-api-1/#initial-value-descriptor

So when the descriptor declaration is omitted, it seems the attribute should serialize the guaranteed-invalid value, which serializes to empty string.

In Chrome:

const styleSheet = new CSSStyleSheet()
styleSheet.insertRule(`
  @property --custom {
    inherits: false;
    syntax: "*";
  }
`)
styleSheet.cssRules.length; // 1
styleSheet.cssRules[0].initialValue; // null
@cdoublev
Copy link
Contributor Author

cdoublev commented Nov 4, 2024

To clarify my point...

Returning null instead of empty string from CSSPropertyRule.initialValue when the descriptor is omitted, seems inappropriate, because its actual value is the guaranteed-invalid value, which is represented (serialized) with an empty string.

To add some arguments...

Similarly, style.getPropertyValue('any-undeclared-property') returns an empty string, and when any @counter-style descriptor is omitted, the corresponding attribute returns empty string. (Their actual value is not the guaranteed-invalid value though).

To give an explicit suggestion:

-   readonly attribute CSSOMString? initialValue;
+   readonly attribute CSSOMString initialValue;
-  - initialValue, of type CSSOMString, readonly, nullable
-    The initial value associated with the @property rule, which may not be present.
+
+  - initialValue, of type CSSOMString, readonly
+    The initial value associated with the @property,
+    or empty string when the descriptor was not specified in the associated rule.

cdoublev added a commit to cdoublev/css that referenced this issue Nov 4, 2024
It should return empty string instead of null, when the descriptor is
omitted.

w3c/css-houdini-drafts#1115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant