<?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>276586</bug_id>
          
          <creation_ts>2024-07-14 01:41:31 -0700</creation_ts>
          <short_desc>Image created with JavaScript will initially ignore `sizes` if it appears after `srcset`</short_desc>
          <delta_ts>2024-07-22 03:24:43 -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>Images</component>
          <version>Safari 17</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=190031</see_also>
          <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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Oliver Joseph Ash">oliverjash</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>cdumez</cc>
    
    <cc>maggotfish</cc>
    
    <cc>m.goleb+bugzilla</cc>
    
    <cc>rniwa</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>yoav</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2046163</commentid>
    <comment_count>0</comment_count>
    <who name="Oliver Joseph Ash">oliverjash</who>
    <bug_when>2024-07-14 01:41:31 -0700</bug_when>
    <thetext>This is similar to https://bugs.webkit.org/show_bug.cgi?id=190031 but not exactly the same.

If `sizes` appears after `srcset`, Safari will initially download the largest entry in `srcset`—ignoring `sizes`—and then later download another entry from `srcset` following the definition of `sizes`.

Reduced test case: https://codepen.io/OliverJAsh/pen/PorqVGM

For comparison, here&apos;s another reduced test case where `sizes` appears before `srcset` instead of afterwards: https://codepen.io/OliverJAsh/pen/MWMwLjp. The issue does not reproduce here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046180</commentid>
    <comment_count>1</comment_count>
    <who name="Oliver Joseph Ash">oliverjash</who>
    <bug_when>2024-07-14 10:10:36 -0700</bug_when>
    <thetext>I just realised a similar bug also affects lazy loading.

If `loading = &apos;lazy&apos;` is set after `src`/`srcset`, Safari downloads the image immediately i.e. it&apos;s not lazy loaded.

Reduced test case: https://codepen.io/OliverJAsh/pen/MWMwMKX

Should I file a separate bug?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046245</commentid>
    <comment_count>2</comment_count>
    <who name="Yoav Weiss">yoav</who>
    <bug_when>2024-07-15 05:35:22 -0700</bug_when>
    <thetext>I believe that the root cause for all of these issues is that WebKit doesn&apos;t implement the &quot;update the image data&quot; [1] as written, and doesn&apos;t queue a microtask before performing step 9 of said algorithm.

As such, attributes that kick off an image load (&quot;src&quot; and &quot;srcset&quot;) do that as soon as they are set, with the attributes already present on the element.

Back in the day when srcset was implemented (by 2014 me..), WebKit did not have a microtask abstraction, so we took this non-compliant path to get support in place. (the lack of microtask abstraction also added significant complexity to the &lt;picture&gt; implementation)

But it seems like nowadays WebKit does have a WebCore accessible microtask abstraction [2]. IIUC, that means that implementing the selection algorithm as specified Should Not Be That Hard™.

That would solve all 3 of these issues, and would potentially enable refactoring of the &lt;picture&gt; selection logic.


[1] https://html.spec.whatwg.org/multipage/images.html#update-the-image-data
[2] https://searchfox.org/wubkat/source/Source/WebCore/dom/EventLoop.h#115</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2047386</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-07-21 01:42:13 -0700</bug_when>
    <thetext>&lt;rdar://problem/132181260&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2047473</commentid>
    <comment_count>4</comment_count>
    <who name="Yoav Weiss">yoav</who>
    <bug_when>2024-07-22 03:24:43 -0700</bug_when>
    <thetext>https://github.com/WebKit/WebKit/pull/31055 addresses this</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>