You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid firing 'load' or 'error' events for <img> when the loaded image didn't change #8492
needs compat analysistopic: eventsEvent handlers, their content and IDL attributes, and the events HTML firestopic: imgImages: img, picture, srcset and sizes, image loading and decoding, and image maps
Currently, in the "update the image data" algorithm for img, if the loaded image is the same as the previous image, it will still fire a load event. Similarly for error (see #4480).
Investigate if it's compatible to change this to avoid firing load or error when there was no change (other than updating the current pixel density).
If this change appears too risky, I think we could first try to change the “load the image data” algorithm to avoid firing “load” and “error” events in more cases. If that is compatible, then it should alleviate the main compat risk for auto-sizes.
One question I have stumbled across on the same topic - should adopting an already-loaded image into a new document should fire a load event?
Chromium and Webkit seem to say no to this - Firefox indicate that it should. Update the image data says "Wait until the element's node document is fully active" which can be interpreted as meaning either the node document at the time that step is reached or when an active document is adopted.
Chromium and Webkit dont fire a load event for below, Firefox does. I think I would expect a load event to be fired.
Test below:
<!doctype html><metacharset="utf-8"><title>Image load after adoption from removed iframe</title><preid="log"></pre><script>functionlog(message){document.getElementById("log").textContent+=`${message}\n`;}constiframe=document.createElement("iframe");iframe.onload=()=>{constimg=iframe.contentDocument.createElement("img");img.onload=()=>{log("image loaded after adoption");log(`width=${img.width} height=${img.height} naturalWidth=${img.naturalWidth} naturalHeight=${img.naturalHeight} complete=${img.complete}`);};img.onerror=()=>{log("image errored after adoption");};img.src="120.png";iframe.contentDocument.body.appendChild(img);iframe.remove();document.body.appendChild(document.adoptNode(img));};document.body.appendChild(iframe);</script>
One other test case is:
<!doctype html><metacharset="utf-8"><title>Already-loaded image adoption from iframe</title><preid="log"></pre><script>functionlog(message){document.getElementById("log").textContent+=`${message}\n`;}constiframe=document.createElement("iframe");iframe.src="blank.html";iframe.onload=()=>{constimg=iframe.contentDocument.createElement("img");img.onload=()=>{// Image is now completely available in the iframe's document.// Reset the handler and adopt into the main document.letfired=false;img.onload=()=>{fired=true;};img.onerror=()=>{fired=true;};iframe.remove();document.body.appendChild(document.adoptNode(img));setTimeout(()=>{log(fired
? "load fired after adoption of already-loaded image"
: "load did not fire after adoption of already-loaded image");},500);};img.onerror=()=>{log("image errored during initial load");};img.src="120.png";iframe.contentDocument.body.appendChild(img);};document.body.appendChild(iframe);</script>
@jdm I think that this might actually be the behavior we expect based on what this issue describes? Since setting e.width *= 2 doesn't update the image (maybe with srcset and lazy loading it could be different), we should expect a single onload event from when the image loads initially, then none from modifying the width.
That said, if we replace e.width *= 2 with e.sizes = "auto" in the example, then chromium and safari send an endless stream of load events, whereas firefox sends two. In firefox it seems to only trigger when e.sizes is changed, rather than set, so one accounts for the load of the image, and the other is the initial set of e.sizes—I think this is the worst of both worlds.
Replacing e.width *= 2 with e.src = "https://joshmatthews.net/portrait.jpg" gives endless streams of onload events in all three browsers, which is what we should expect from all these test cases according to the current spec, but not from this issue.
In any case, the spec probably needs to be updated here to clarify what the intended behavior is.
needs compat analysistopic: eventsEvent handlers, their content and IDL attributes, and the events HTML firestopic: imgImages: img, picture, srcset and sizes, image loading and decoding, and image maps
Activity
shannonbooth commentedon May 26, 2026
One question I have stumbled across on the same topic - should adopting an already-loaded image into a new document should fire a load event?
Chromium and Webkit seem to say no to this - Firefox indicate that it should. Update the image data says "Wait until the element's node document is fully active" which can be interpreted as meaning either the node document at the time that step is reached or when an active document is adopted.
Chromium and Webkit dont fire a load event for below, Firefox does. I think I would expect a load event to be fired.
Test below:
One other test case is:
LibWeb: Use the node document realm for image requests
LibWeb: Use the node document realm for image requests
jdm commentedon Aug 4, 2026
I'm confused—the following testcase only reports a single load event across Firefox, Safari, and Chrome:
This doesn't appear to match what the specification describes or what this issue describes.
evlasics commentedon Aug 4, 2026
@jdm I think that this might actually be the behavior we expect based on what this issue describes? Since setting
e.width *= 2doesn't update the image (maybe with srcset and lazy loading it could be different), we should expect a singleonloadevent from when the image loads initially, then none from modifying the width.That said, if we replace
e.width *= 2withe.sizes = "auto"in the example, then chromium and safari send an endless stream of load events, whereas firefox sends two. In firefox it seems to only trigger whene.sizesis changed, rather than set, so one accounts for the load of the image, and the other is the initial set ofe.sizes—I think this is the worst of both worlds.Replacing
e.width *= 2withe.src = "https://joshmatthews.net/portrait.jpg"gives endless streams ofonloadevents in all three browsers, which is what we should expect from all these test cases according to the current spec, but not from this issue.In any case, the spec probably needs to be updated here to clarify what the intended behavior is.
fix(engine): img relevant mutations 三根因——referrerpolicy 空串态 + SOURCE …