<?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>313840</bug_id>
          
          <creation_ts>2026-05-01 12:46:30 -0700</creation_ts>
          <short_desc>REGRESSION (Safari 26): setProperty fails to apply !important priority to existing inline style if integer value is &lt;= 255, breaking cascade</short_desc>
          <delta_ts>2026-05-13 07:38:58 -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>Safari 26</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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>285900</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jacob Goldman">jmgoldman</reporter>
          <assigned_to name="Ahmad Saleem">ahmad.saleem792</assigned_to>
          <cc>karlcow</cc>
    
    <cc>koivisto</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2206648</commentid>
    <comment_count>0</comment_count>
    <who name="Jacob Goldman">jmgoldman</who>
    <bug_when>2026-05-01 12:46:30 -0700</bug_when>
    <thetext>When an element has an existing inline style containing an integer value of 255 or lower (e.g., `width: 200px`), using `CSSStyleDeclaration.setProperty()` to re-apply the exact same value string alongside the `!important` priority flag silently fails.

Because the priority flag is dropped, the inline style fails to override conflicting `!important` rules in the global stylesheet, resulting in a layout rendering failure. 

**Steps to Reproduce:**
Save the following code as an HTML file and open it in Safari:

```html
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;style&gt;
    /* Global stylesheet with !important */
    #test-el {
      width: 100px !important; 
    }
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;div id=&quot;test-el&quot;&gt;&lt;/div&gt;

  &lt;script&gt;
    const el = document.getElementById(&apos;test-el&apos;);

    // 1. Set standard inline style.
    el.style.setProperty(&apos;width&apos;, &apos;255px&apos;);
    console.log(&quot;offsetWidth (from global):&quot;, el.offsetWidth);
    console.log(&quot;width priority:&quot;, el.style.getPropertyPriority(&apos;width&apos;));

    // 2. (fails) Attempt to upgrade priority to !important with the exact same value
    el.style.setProperty(&apos;width&apos;, &apos;255px&apos;, &apos;important&apos;);
    console.log(&quot;offsetWidth (from inline):&quot;, el.offsetWidth);
    console.log(&quot;width priority:&quot;, el.style.getPropertyPriority(&apos;width&apos;));

    // 3. (works) Attempt to upgrade priority to !important with a value &gt;= uint8.
    el.style.setProperty(&apos;width&apos;, &apos;256px&apos;, &apos;important&apos;);
    console.log(&quot;offsetWidth (from inline):&quot;, el.offsetWidth);
    console.log(&quot;width priority:&quot;, el.style.getPropertyPriority(&apos;width&apos;));
  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
```

**Actual Results:**
```
[Log] offsetWidth (from global): – 100 (minimal.html, line 19)
[Log] width priority: – &quot;&quot; (minimal.html, line 20)
[Log] offsetWidth (from inline): – 100 (minimal.html, line 24)
[Log] width priority: – &quot;important&quot; (minimal.html, line 25)
[Log] offsetWidth (from inline): – 256 (minimal.html, line 29)
[Log] width priority: – &quot;important&quot; (minimal.html, line 30)
```
The `!important` flag was ignored with 255px, the engine skipped style invalidation, and the global stylesheet incorrectly won the cascade until 256px was provided.

**Expected Results:**
[Log] offsetWidth (from global): – 100 (minimal.html, line 19)
[Log] width priority: – &quot;&quot; (minimal.html, line 20)
[Log] offsetWidth (from inline): – 255 (minimal.html, line 24)
[Log] width priority: – &quot;important&quot; (minimal.html, line 25)
[Log] offsetWidth (from inline): – 256 (minimal.html, line 29)
[Log] width priority: – &quot;important&quot; (minimal.html, line 30)
The inline `!important` style should override the stylesheet `!important` style, rendering the element at 200px wide.

**Build Date &amp; Hardware:**
Safari 26.0 on macOS Sequoia / macOS Sonoma.

**Additional Builds and Platforms:**
Doesn&apos;t Occur On Safari v18.6.
Doesn&apos;t Occur On Google Chrome or Mozilla Firefox.

**Additional Information:**

*Fact:* If the integer value used in the script is changed to `256px` or higher (e.g., `257px`), the bug does not occur.
*Fact:* Calling `el.style.removeProperty(&apos;width&apos;)` immediately before the `setProperty` call successfully works around the issue, forcing the layout engine to apply the priority and render at `200px`.

*Speculation (from LLM):* This appears to be a regression in WebCore&apos;s mutation optimization (`MutableStyleProperties::setProperty`), specifically interacting with the `CSSValuePool`. WebKit caches CSS primitive values between 0 and 255. Because both the existing inline value and the incoming `setProperty` value use the cached pointer for `200px`, the engine performs a fast-path memory address comparison, incorrectly concludes the style has not changed, and aborts the update before parsing the priority flag or invalidating the layout. Values of 256+ exceed the cache, forcing a new memory allocation, which bypasses the pointer equality check and allows the cascade to resolve properly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2206912</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-05-02 12:11:56 -0700</bug_when>
    <thetext>&lt;rdar://problem/176099619&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209629</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-05-11 00:58:57 -0700</bug_when>
    <thetext>It may be the result of the optimization done in Bug 285900.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209631</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-05-11 01:04:23 -0700</bug_when>
    <thetext>Jakob, thanks for the report. Did it break one of the websites you are working on?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209677</commentid>
    <comment_count>4</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-05-11 03:44:23 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/64670</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209721</commentid>
    <comment_count>5</comment_count>
    <who name="Jacob Goldman">jmgoldman</who>
    <bug_when>2026-05-11 07:43:40 -0700</bug_when>
    <thetext>(In reply to Karl Dubost from comment #3)
&gt; Jakob, thanks for the report. Did it break one of the websites you are
&gt; working on?

Thank you all for the quick fix. I work on Google display ads, this may have broken styling on certain ad formats but depends on any collisions with the website&apos;s own !important styles (bug was surfaced in a unit test). We will run an experiment soon with a workaround to remove the style before adding it back with important.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2210502</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-05-13 07:38:55 -0700</bug_when>
    <thetext>Committed 313159@main (e297a5ca30f3): &lt;https://commits.webkit.org/313159@main&gt;

Reviewed commits have been landed. Closing PR #64670 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>