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 24312 - <img> should reload (and re-resolve URLs) when switching Documents
Summary: <img> should reload (and re-resolve URLs) when switching Documents
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: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on: 23810
Blocks:
  Show dependency treegraph
 
Reported: 2014-01-16 19:02 UTC by Adam Klein
Modified: 2014-02-24 22:53 UTC (History)
9 users (show)

See Also:


Attachments

Description Adam Klein 2014-01-16 19:02:17 UTC
<img> (and probably similar elements, like <audio>) should reload (and re-resolve URLs) when switching Documents. This matches behavior in at least Blink, WebKit, and Gecko.

I suspect something similar should happen to other resource-loading elements, but I haven't tested them (e.g., <audio> and <video>).
Comment 1 Ian 'Hixie' Hickson 2014-01-16 21:54:17 UTC
It definitely shouldn't happen for <audio>/<video>. That's clearly specified. There's nothing special about being inserted into a document, whether it's the owner doc or not. Firefox and Safari do this right. Chrome has a bug with it:

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2755
Comment 2 Ian 'Hixie' Hickson 2014-01-16 22:34:39 UTC
With images, if the resolved URL is different, Firefox does load the image afresh:

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2758 (same)
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2759 (different)

Chrome and Safari reload the image even if the URL resolves unchanged.

Anyone got IE around to test?
Comment 3 Ian 'Hixie' Hickson 2014-01-17 21:49:47 UTC
Firefox actually does this when you insert the node into the other document, not when you change the ownerDocument. Chrome does it when you change the ownerDocument. Which do we want to do, if either?

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2765
Comment 4 Boris Zbarsky 2014-01-17 22:18:23 UTC
Firefox generally reloads images on insert into DOM if the image URI has changed in the process, since we support xml:base.

If xml:base support goes away, then doing it on adopt makes some sense...
Comment 5 Ian 'Hixie' Hickson 2014-02-04 21:41:44 UTC
Adam, do you have an opinion on when you want <img> to re-load? Adoption? Insertion after adoption?
Comment 6 Adam Klein 2014-02-04 21:42:56 UTC
(In reply to Ian 'Hixie' Hickson from comment #5)
> Adam, do you have an opinion on when you want <img> to re-load? Adoption?
> Insertion after adoption?

Adoption would be consistent with existing WebKit and Blink behavior, so I guess that's my default preference.
Comment 7 Boris Zbarsky 2014-02-04 21:49:44 UTC
What happens in the insert-into-other-document case (which auto-adopts).  Should the load happen after the adopt but before the insert in that case, or after the insert?

We can obviously add a special case to load if the URI changed on adopt in Gecko.  I would prefer to not force a load if the URI has not changed.
Comment 8 Adam Klein 2014-02-04 22:02:52 UTC
(In reply to Boris Zbarsky from comment #7)
> What happens in the insert-into-other-document case (which auto-adopts). 
> Should the load happen after the adopt but before the insert in that case,
> or after the insert?

Since Blink doesn't support xml:base for <img>, this doesn't matter for us (unless I'm missing something).

> We can obviously add a special case to load if the URI changed on adopt in
> Gecko.  I would prefer to not force a load if the URI has not changed.

We should probably have such a special case in Blink if we don't already.
Comment 9 Boris Zbarsky 2014-02-04 22:07:08 UTC
> this doesn't matter for us (unless I'm missing something).

It matters once the load depends on contextual information (c.f. <picture>).  It also matters depending on the outcome of the discussion in bug 20976.
Comment 10 Adam Klein 2014-02-04 22:12:54 UTC
> It matters once the load depends on contextual information (c.f. <picture>).
> It also matters depending on the outcome of the discussion in bug 20976.

Good points. At the moment, adoption happens before insertion, and so loading is triggered before insertion as well. If we wanted to change that it should be doable, though (given, as I noted before, that there aren't any web compat issues for us).
Comment 11 Adam Klein 2014-02-04 22:14:53 UTC
See also this active thread on blink-dev: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/hKj2OsvZl1g
Comment 12 Simon Pieters 2014-02-05 10:03:32 UTC
As for <picture>, I think it makes sense to rerun the selection algorithm when an <img> is moved to a different document. (This seems separate from the question about whether to re-resolve the URLs and whether to reload if the resulting URL is the same.)
Comment 13 Ian 'Hixie' Hickson 2014-02-07 17:57:31 UTC
So what's our conclusion here? Would this work?:

 - on a straight adoption, reresolve the URL, and if it changed, reload
 - on an adoption that is part of an insertion, wait until the insertion is done,
   and then reresolve and, if it changed, reload
 - on all other base URL changes, do nothing
Comment 14 Boris Zbarsky 2014-02-07 18:02:18 UTC
Anne, what did we decide about when the adopt handlers from insert-and-adopt run?  Seems like fundamentally we should do this from those, like other base URI fixup...
Comment 15 Anne 2014-02-10 10:43:35 UTC
Agreed. So once we have the custom elements machinery working, timing-wise this adopt-callback would run just before the method that caused the adopt to happen returns. HTML would then plug base URL fixup on it and reloading for various elements.

For now I'll run the adopt steps synchronously awaiting some kind of mechanism to make them run a tad later.
Comment 16 Ian 'Hixie' Hickson 2014-02-10 21:13:27 UTC
So you're saying there'll be a hook for HTML to use?
Comment 17 Anne 2014-02-11 13:27:56 UTC
http://dom.spec.whatwg.org/#concept-node-adopt-ext is the callback hook. What I'm saying is that currently it runs sync, but once custom element integration has been improved it will run slightly later.
Comment 18 Ian 'Hixie' Hickson 2014-02-11 19:49:14 UTC
Will it run after insertion in the case of an adoption that happens as part of insertion into a subtree with a different owner document?
Comment 19 Anne 2014-02-12 11:14:17 UTC
Yes, it would run after the insertion. E.g. if you do appendChild() it would run just before that method returns. 

(I wish the custom element had talked to you about what they are doing so I don't have to do all their coordination work :/)
Comment 20 Dimitri Glazkov 2014-02-13 17:53:38 UTC
(In reply to Anne from comment #19)
> Yes, it would run after the insertion. E.g. if you do appendChild() it would
> run just before that method returns. 
> 
> (I wish the custom element had talked to you about what they are doing so I
> don't have to do all their coordination work :/)

Here's a quick catch-up/recap:

We're adding adopt node callback to custom elements (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24577). The timing of when this callback is invoked will be shifted relative to when it is enqueued, as Anne indicated early.

The reason for the timing change is fulfilling UAs wish not to allow author code to run in the middle of its work. This is why custom elements have the element/callback queues (http://w3c.github.io/webcomponents/spec/custom/#enqueuing-and-invoking-callbacks).

So yes, the timing of the callback may depend on whether the callback is trusted by the UA (in which case it is invoked right away) or not (in which case it is invoked at the time that UA considers it safe).

As an aside, this time-shifting plumbing should probably be made into its own primitive (a write barrier of sorts), which would enable UAs to arbitrarily erect this barrier to protect integrity of certain DOM operations (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24655)
Comment 21 Ian 'Hixie' Hickson 2014-02-14 21:48:44 UTC
Ok, I don't really see why custom elements are relevant here then.

As far as I can tell, the bug here is just that <img> should reevaluate itself when #concept-node-adopt-ext is invoked.
Comment 22 Dimitri Glazkov 2014-02-15 00:15:33 UTC
(In reply to Ian 'Hixie' Hickson from comment #21)
> Ok, I don't really see why custom elements are relevant here then.
> 
> As far as I can tell, the bug here is just that <img> should reevaluate
> itself when #concept-node-adopt-ext is invoked.

Sounds about right.
Comment 23 contributor 2014-02-24 22:53:46 UTC
Checked in as WHATWG revision r8509.
Check-in comment: Make <img> reload if inserting it into a new doc causes the URL to change (note that exactly what this does depends on whether the browser's 'list of available images' is maintained per-Doc, or whether there's only one list per origin)
http://html5.org/tools/web-apps-tracker?from=8508&to=8509