This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24712 - <img>: Should probably not fire load if selected source is the same as the last selected source. (step 7.3)
Summary: <img>: Should probably not fire load if selected source is the same as the la...
Status: RESOLVED MOVED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other All
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-18 12:37 UTC by contributor
Modified: 2019-03-29 21:03 UTC (History)
4 users (show)

See Also:


Attachments

Description contributor 2014-02-18 12:37:23 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html
Multipage: http://www.whatwg.org/C#update-the-image-data
Complete: http://www.whatwg.org/c#update-the-image-data
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/

Comment:
Should probably not fire load if selected source is the same as the last
selected source. (step 7.3)

Posted from: 90.230.218.37 by simonp@opera.com
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.90 Safari/537.1
Comment 1 Ian 'Hixie' Hickson 2014-02-24 23:24:46 UTC
This test shows that all browsers fire 'load' even if it's the same source:
   http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2846
Comment 2 Ian 'Hixie' Hickson 2014-02-24 23:25:30 UTC
(It also shows that Chrome/Safari don't seem to have a "list of available images", which is interesting.)
Comment 3 Ian 'Hixie' Hickson 2014-02-25 19:25:39 UTC
Marking WORKSFORME. If you disagree, please reopen but with a test case demonstrating why the test above is wrong.

Actually, the test above can be misleading if the load is slow for some reason. Here's a test that has a bigger margin for handling that:
   http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2848
Comment 4 Simon Pieters 2014-02-26 08:38:17 UTC
The test seems right, but I think this is bad for srcset/picture, where you might end up with seemingly random 'load' events even though the image didn't change.
Comment 5 Ian 'Hixie' Hickson 2014-02-26 15:37:56 UTC
srcset="" doesn't fire 'load' if it doesn't change. There's a separate algorithm for that case.
Comment 6 Simon Pieters 2014-02-27 14:12:33 UTC
Yeah, I know, so I guess it's not much of an issue for srcset itself, but for <picture> it's kind of an issue because there are several DOM mutations that trigger these steps. It would be nice to be able to run the steps without side-effect if the selected URL ends up being the same.
Comment 7 Ian 'Hixie' Hickson 2014-02-28 21:53:00 UTC
A design that uses multiple elements for this is broken exactly because of issues like this. I pointed that out well over a year ago already, when speccing srcset.
Comment 8 Ian 'Hixie' Hickson 2014-03-12 18:36:18 UTC
I don't understand the problem here.
Comment 9 Simon Pieters 2014-03-19 07:32:46 UTC
I disagree that it is broken. It's more complex, I agree, and I pointed that out also, but the fix for this bug is trivial.

The bug is this:

consider <img id=x src="foo.jpg" crossorigin=""> with foo.jpg loaded, then x.crossOrigin = 'anonymous';. This fires a load event but the image is the same.

or <img id=y srcset="foo.jpg 1x"> with foo.jpg loaded, then y.srcset += ' ';.

or <picture><img src="foo.jpg"></picture> with foo.jpg loaded, then a <source> element with no attributes is inserted before the <img>.

Possibly it's not much of a problem to fire load in the above cases, it just seemed unnecessary and an area where UAs could potentially optimize if there were no observable side-effects.
Comment 10 Ian 'Hixie' Hickson 2014-03-19 20:44:39 UTC
In the crossorigin case, the image might not be the same. You have to redownload it to find out.

In the srcset += ' ' case... I think it's ok to fire 'load' again. After all, you changed the data that impacts the image selection, so you should expect the image selection to run again. If we didn't fire 'load', how would you know nothing had gone wrong during the image selection update?

The <picture> case is misguided and the element shouldn't exist in the first place, IMHO, so I have no particular comment on the specifics there.
Comment 11 Simon Pieters 2014-03-20 11:13:15 UTC
(In reply to Ian 'Hixie' Hickson from comment #10)
> In the crossorigin case, the image might not be the same. You have to
> redownload it to find out.

No, the state of the attribute is the same, and the 'update the image data' algorithm uses the state. The steps don't redownload AFAICT.

> In the srcset += ' ' case... I think it's ok to fire 'load' again. After
> all, you changed the data that impacts the image selection, so you should
> expect the image selection to run again. If we didn't fire 'load', how would
> you know nothing had gone wrong during the image selection update?

I guess that's fair enough.

> The <picture> case is misguided and the element shouldn't exist in the first
> place, IMHO, so I have no particular comment on the specifics there.

You can ignore it if you like but it seems it is being implemented...
Comment 12 Domenic Denicola 2019-03-29 21:03:13 UTC
At a quick glance, https://github.com/whatwg/html/issues/3709 indicates that this was specced to not fire the load event, but browsers do anyway, and we need to fix the spec to match them. Let's consolidate discussion there.