<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>247741</bug_id>
          
          <creation_ts>2022-11-10 09:32:58 -0800</creation_ts>
          <short_desc>cssText can serialize duplicated declarations</short_desc>
          <delta_ts>2025-06-02 15:02:45 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>247734</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Oriol Brufau">obrufau</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>karlcow</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1911560</commentid>
    <comment_count>0</comment_count>
    <who name="Oriol Brufau">obrufau</who>
    <bug_when>2022-11-10 09:32:58 -0800</bug_when>
    <thetext>Run this:

    document.body.style.cssText = &quot;margin: var(--m)&quot;;
    document.body.style.marginTop = &quot;1px&quot;;
    document.body.style.cssText;

Expected: &quot;margin-top: 1px; margin-right: ; margin-bottom: ; margin-left: ;&quot;
Actual: &quot;margin-top: 1px; margin: var(--m);&quot;

margin-top appears twice (once explicitly and once via margin shorthand).
The problem is that margin-top detect that it can&apos;t be serialized via shorthand so it appears as a longhand, but then bug 247734 prevents other longhands from realizing it and they serialize via the shorthand, which overrides margin-top.
Note the duplication only happens if the different longhand(s) appear first, otherwise it&apos;s just bug 247734 without duplication.

Run this:

    document.body.style.cssText = &quot;grid-area: var(--a); grid-row-start: 1&quot;;
    document.body.style.cssText;

Expected: &quot;grid-row-end: ; grid-column-start: ; grid-column-end: ; grid-row-start: 1;&quot;
Actual: &quot;grid-area: var(--a); grid-row-start: 1;&quot;

That&apos;s a similar case, but unlike for margin, we get a duplicated grid-row-start even if it&apos;s not the 1st one.
The reason is that cssText doesn&apos;t try to serialize using the grid-area shorthand, but var() can bypass this.
So the shorthand serializes due to the longhands set to a pending-substitution value, and then grid-row-start doesn&apos;t check whether grid-area has already been used.
TBH in this specific case the actual serialization seems better than the expected one (see https://github.com/w3c/csswg-drafts/issues/2515), but it&apos;s a non-intentional mistake.

Run this:

    document.body.style.cssText = &quot;background-position: var(--b)&quot;;
    document.body.style.backgroundPositionX = &quot;0px&quot;;
    document.body.style.cssText;

Expected: &quot;background-position-x: 0px; background-position-y: ;&quot;
Actual: &quot;background-position: var(--b); background-position-x: 0px;&quot;

Another similar case, but here background-position-x is manually inserted at the end: https://searchfox.org/wubkat/rev/7a292520f6b12e8d4d9001d1480474b5c83cb0f8/Source/WebCore/css/StyleProperties.cpp#1890
In bug 190753 I added a check to avoid this if already serialized by the all shorthand, but the background and background-position shorthands are not checked.
In fact this acts as a workaround for bug 247734 so it&apos;s not that bad, but both should be fixed.

Run this:

    document.body.style.webkitMask = &quot;none 0px 0px&quot;;
    document.body.style.cssText;

Expected: &quot;-webkit-mask: none 0px 0px;&quot;
Actual: &quot;mask-image: none; -webkit-mask: none 0px 0px; -webkit-mask-position-x: 0px; -webkit-mask-position-y: 0px;&quot;

This case doesn&apos;t use var(), but it&apos;s still a similar problem.
The -webkit-mask shorthand is typically avoided, except for -webkit-mask-clip.
So first mask-image avoids -webkit-mask-clip and serializes as-is, then -webkit-mask-clip sees a possible serialization with -webkit-mask and uses it even if mask-image has already present, and then following longhands will not realize that they have been covered by -webkit-mask.

There may be similar cases for the mask shorthand but it&apos;s serialization seems quite broken.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1911853</commentid>
    <comment_count>1</comment_count>
    <who name="Oriol Brufau">obrufau</who>
    <bug_when>2022-11-11 10:29:35 -0800</bug_when>
    <thetext>First 2 cases addressed by bug 247734.

Now it&apos;s:

    document.body.style.cssText = &quot;background-position: var(--b)&quot;;
    document.body.style.backgroundPositionX = &quot;0px&quot;;
    document.body.style.cssText;

Expected: &quot;background-position-x: 0px; background-position-y: ;&quot;
Actual: &quot;background-position-y: ; background-position-x: 0px;&quot;
So just a non-canonical order.

And I think the 4th case was missing a 1st line, but oh well:

    document.body.style.cssText = &quot;-webkit-mask: none 0px 0px&quot;;
    document.body.style.cssText;

Expected: &quot;-webkit-mask: none 0px 0px;&quot;
Actual: &quot;mask-image: none; -webkit-mask-position-x: 0px; -webkit-mask-position-y: 0px; -webkit-mask: none 0px 0px;&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1912391</commentid>
    <comment_count>2</comment_count>
    <who name="Oriol Brufau">obrufau</who>
    <bug_when>2022-11-14 12:05:14 -0800</bug_when>
    <thetext>Order of background-position-x/y fixed by bug 247879.

So it&apos;s just with mask properties now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913208</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-11-17 09:33:16 -0800</bug_when>
    <thetext>&lt;rdar://problem/102471167&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>