Closed cdoublev closed 1 month ago
In practice, the difference can be observed as such:
document.body.style.gridGap = "var(--gap)";
document.body.style.gap;
Firefox and WebKit say "var(--gap)"
because they implement grid-gap
as an alias of gap
.
Blink says ""
because it implements grid-gap
and gap
as independent shorthands.
In practice, the difference can be observed as such
Do you mean the difference between a simple alias and a legacy shorthand?
Blink says
""
because it implementsgrid-gap
andgap
as independent shorthands.
Is this the expected behavior of a legacy shorthand? If so, I do not understand. grid-gap
is a shorthand for gap
which is a shorthand for row-gap
and column-gap
, so the parsed value for grid-gap
must expand to declarations for both longhands. Why gap
would then serialize to ''
?
EDIT: oh right, ok, it is specific to substitution-value, I will have to think harder to understand how it could be wrong to not serialize gap
with the substitution-value specified for grid-gap
.
Yes, this is just when using var()
. For these gap properties I think it would be fine, but in general it would not, e.g.
document.body.style.cssText = "--bb: page; break-before: var(--bb)";
document.body.style.pageBreakBefore; // ""
It can't be var(--bb)
since page-break-before: page
would be invalid.
Then when syntaxes are different, UAs must implement the legacy property as a legacy shorthand, otherwise they can choose the mechanism they want.
I would not want to stray too far from the topic of this issue (which is to allow aliasing grid-*-gap
as a simple alias), but did you had discussions about serializing the legacy shorthand with var()
as a specified value (when it was declared for the target property), but with empty string as a computed/resolved value? This may avoid these confusing serializations:
style.pageBreakAfter = 'var(--custom)'
style.cssText; // 'break-after: ;'
style.breakAfter = 'var(--custom)'
style.cssText; // 'break-after: var(--custom);'
But how to serialize these cases may not be fully defined though (cf. #3109).
This could maybe be addressed as part of #2515? https://drafts.csswg.org/css-cascade-4/#legacy-shorthand says
CSSOM will not use them when serializing declarations
but I think they should be used when a longhand has a pending-substitution value linked to the legacy shorthand. WebKit does this:
style.pageBreakAfter = 'always'
style.cssText; // 'break-after: page;'
style.pageBreakAfter = 'var(--custom)'
style.cssText; // 'page-break-after: var(--custom);'
I was thinking to serializing the legacy shorthand with getPropertyValue()
:
style['--custom'] = 'recto'
style.breakAfter = 'var(--custom)'
style.pageBreakAfter; // 'var(--custom)'
computedStyle.pageBreakAfter; // ''
But yeah, "using" it in a style block also makes sense to me, and I am fine with discussing it in #2515. I subscribed to it.
Based on @Loirooriol 's comment in a Chromium code review, it sounds like:
I will also admit when reading the spec that I didn't catch the distinction that these weren't aliases.
(We should probably also add helper functions to parsing-testcommon.js
for testing that something is one or the other of these types of aliases, based on the technique in https://github.com/w3c/csswg-drafts/issues/8014#issuecomment-1302965043 .)
The CSS Working Group just discussed [css-align-3] `grid-*-gap` should be aliases instead of shorthands
, and agreed to the following:
RESOLVED: Make grid*gap properties be legacy name aliases
grid-row-gap
,grid-column-gap
,grid-gap
, are defined to be treated as legacy shorthands instead of legacy name aliases, but they must take the same grammar as the property they are aliasing, whereas CSS Cascade defines:I did not quite understand the whole discussions in #866 (especially the meeting transcript) that led to the changes in CSS Cascade for the above definition and the definition of legacy shorthands, so I am not sure the resolution is you must use legacy name aliasing when the syntax is the same. I also note that the details of the aliasing mechanism is intentionally left up to the UA for some legacy properties whose syntax is the same as the new property (eg.
-webkit-user-select
).