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 20397 - [Custom]: Consider changing elementupgrade to a mutation observer
Summary: [Custom]: Consider changing elementupgrade to a mutation observer
Status: RESOLVED INVALID
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 17103
  Show dependency treegraph
 
Reported: 2012-12-14 23:02 UTC by Dimitri Glazkov
Modified: 2013-04-10 20:47 UTC (History)
2 users (show)

See Also:


Attachments

Description Dimitri Glazkov 2012-12-14 23:02:28 UTC
"On UPGRADE, fire an event named elementupgrade with its bubbles attribute set to true."
Comment 1 Olli Pettay 2012-12-14 23:07:26 UTC
Well, elementupgrade isn't any kind of change to DOM, so using mutation observer
for it feels a bit like misuse of the API.
Comment 2 Dimitri Glazkov 2012-12-14 23:10:19 UTC
(In reply to comment #1)
> Well, elementupgrade isn't any kind of change to DOM, so using mutation
> observer
> for it feels a bit like misuse of the API.

It totally is a DOM change, right? There's a whole bunch of replacement that happened and the DOM node that fires elementupgrade has just been inserted into DOM.
Comment 3 Dimitri Glazkov 2012-12-14 23:13:01 UTC
The biggest issue here is that upgrading a tree full of custom elements would be incredibly chatty and slow. Elliot pointed out that this event sounds a lot like a mutation event.
Comment 4 Olli Pettay 2012-12-14 23:14:12 UTC
Replacements are DOM mutations and of course there will be a mutation record
for each node removal or insertion. They are just normal DOM mutations.
But upgrade itself isn't a DOM mutation.
Comment 5 Olli Pettay 2012-12-14 23:14:57 UTC
upgrade event sounds more like load event.
Comment 6 Dimitri Glazkov 2012-12-14 23:15:46 UTC
(In reply to comment #4)
> Replacements are DOM mutations and of course there will be a mutation record
> for each node removal or insertion. They are just normal DOM mutations.
> But upgrade itself isn't a DOM mutation.

But the upgrade algorithm specifically suppresses these mutation records now: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-element-upgrade
Comment 7 Olli Pettay 2012-12-14 23:16:40 UTC
Oh, that sounds like a bug.
Comment 8 Dimitri Glazkov 2012-12-14 23:27:06 UTC
(In reply to comment #7)
> Oh, that sounds like a bug.

My thinking here was to keep element upgrade as quiet and least side-effectey as possible, and only signal when the upgrade is done.

Also, in cases when we (the browser) know that the author doesn't hold JS references to the element that's being replaced, we (the browser) don't _need_ to do actually do any replacing. In which case, we don't have to generate artificial mutation records.
Comment 9 Olli Pettay 2012-12-14 23:30:36 UTC
Mutation observer is about observing changes to DOM.
Special cases make the API inconsistent, and inconsistency in APIs should
be avoided.
If you don't want to get mutation records, don't observe those elements.

What we could do perhaps is to add some kind of filter to MutationObserver,
but not sure it would help much in this case.
Comment 10 Dominic Cooney 2012-12-17 01:02:24 UTC
I think you need to minimize the time between when the new element is inserted into the DOM but the custom element’s code has not run.

Specifically, if that window is non-zero, JavaScript has to be prepared to handle custom elements in *three* states: not upgraded, "half upgraded" (after the DOM modification but before the notification), and upgraded. Handling a third state will be tedious and confusing.

For this reason I think an upgrade event is better than a MutationObserver, because we have more control over the timing of the upgrade event and can fire it "immediately".

Such an event goes against the rationale for deprecating mutation events in favor of MutationObservers in the first place–that the nesting of such events is confusing, etc.

I believe that argument does not apply in this case, because the UA can control when it fires upgrade events so that they are never nested.
Comment 11 Dimitri Glazkov 2013-01-16 18:14:10 UTC
(In reply to comment #10)

The discussion about suppressing mutation events is in bug 20490.
Comment 12 Dimitri Glazkov 2013-04-10 20:47:26 UTC
elementupgrade is no more. The upgrade process has been replaced with prototype swizzling.