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 24958 - <img>: When exactly should "update the image data" run?
Summary: <img>: When exactly should "update the image data" run?
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Simon Pieters
QA Contact:
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-06 15:45 UTC by contributor
Modified: 2015-09-16 12:44 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2014-03-06 15:45:13 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html
Multipage: http://www.whatwg.org/C#the-img-element
Complete: http://www.whatwg.org/c#the-img-element
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/

Comment:
When exactly should "update the image data" run?

Posted from: 98.110.194.132 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:30.0) Gecko/20100101 Firefox/30.0
Comment 1 Boris Zbarsky 2014-03-06 15:46:25 UTC
For example, if you have an img and you do:

  img.crossOrigin = img.crossOrigin;

does that update the image data?

What about:

  img.src = img.src;

?

Note that I believe it's a web compat requirement that the latter do so (at least to the extent of resetting GIF animations) but it would be nice if the former did not.
Comment 2 Boris Zbarsky 2014-03-06 15:53:23 UTC
Oh, and I bet whether "update the image data" runs is observable via load events on the image or something, not just via whether the image data changes.  :(
Comment 3 Ian 'Hixie' Hickson 2014-03-06 19:15:03 UTC
The spec says:

# A user agent that obtains images immediately must synchronously update the image 
# data of an img element whenever that element is created with a src attribute, a 
# srcset attribute, or both. A user agent that obtains images immediately must 
# also synchronously update the image data of an img element whenever that element 
# has its src, srcset, or crossorigin attribute set, changed, or removed, and 
# whenever that element's adopting steps are run.

Is that sufficiently clear?
Comment 4 Boris Zbarsky 2014-03-06 19:21:15 UTC
I'm not sure it is.

Specifically, consider this case:

  img.setAttribute("src", img.getAttribute("src"));

Is that the attribute being "changed"?  If not, is it being set?  If yes, then why does the spec draw a distinction between "changed" and "set"?

Specifically, if the usage of "set" and "changed" here refer to http://dom.spec.whatwg.org/#attribute-is-set and company then we should not be mentioning "changed" at all?  All we want from there is "set" or "removed".  If we're not using those terms, then we should define the terms we're using.
Comment 5 Boris Zbarsky 2014-03-06 19:22:11 UTC
And again, that would imply that setting .crossOrigin to its existing value reloads the image, which seems suboptimal...
Comment 6 Boris Zbarsky 2014-03-06 19:23:20 UTC
Oh, and one other related thing: Gecko updates the image data differently on src sets and other changes (e.g. src sets force a cache validity check even if the URI did not change)...
Comment 7 Boris Zbarsky 2014-03-06 19:23:43 UTC
...and I seem to recall the web depending on that.
Comment 8 Ian 'Hixie' Hickson 2014-03-06 22:47:53 UTC
From http://www.whatwg.org/specs/web-apps/current-work/#dom-trees :
# A content attribute is said to change value only if its new value is
# different than its previous value; setting an attribute to a value it
# already has does not change it.
Comment 9 Boris Zbarsky 2014-03-06 23:13:12 UTC
OK, but the use of "changed" here doesn't link to that definition, and the DOM uses a different one.

Can you see why I was being confused what the spec was requiring yet?

And again, setting src to its existing value should not be a no-op last I checked.  One of the few exceptions.
Comment 10 Ian 'Hixie' Hickson 2014-03-07 23:04:32 UTC
I agree that the prose is confusing (though it long predates the DOM spec).

Setting the IDL attribute:
  http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2874
  http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2875

Setting the content attribute:
  http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2876

Firefox doesn't reset the animation, as far as I can tell.
Comment 11 Boris Zbarsky 2014-03-08 05:13:16 UTC
> Firefox doesn't reset the animation, as far as I can tell.

Firefox 27 regressed this, along with some other src setting stuff.  Try Firefox 26 or earlier...  See <https://bugzilla.mozilla.org/show_bug.cgi?id=980243>.  Fixing that bug is what prompted me to look at this part of the spec, btw.
Comment 12 Ian 'Hixie' Hickson 2014-03-10 21:36:48 UTC
Ah, good to know. Thanks.
Comment 13 Simon Pieters 2014-06-16 12:07:13 UTC
Run 'update the image data' for img.src = img.src case.
https://github.com/ResponsiveImagesCG/picture-element/commit/56512126f8ac4d69f58807df6b6cfe6d7df20ccb

Make img.src = img.src restart the animation.
https://github.com/ResponsiveImagesCG/picture-element/commit/d2888fb80c2b35070034a6c3ad5cf90a889d955f

Hixie, please move the "restart the animation" definition to the Rendering section. Thanks.
Comment 14 Ian 'Hixie' Hickson 2014-08-28 19:03:31 UTC
Done; back to you to remove the relevant paragraph in the <img> section.
Comment 15 contributor 2014-08-28 19:03:49 UTC
Checked in as WHATWG revision r8725.
Check-in comment: Move 'restart the animation' down
http://html5.org/tools/web-apps-tracker?from=8724&to=8725