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 28544 - Custom elements should not upgrade elements by setting prototype
Summary: Custom elements should not upgrade elements by setting prototype
Status: RESOLVED MOVED
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:
 
Reported: 2015-04-22 23:45 UTC by Ryosuke Niwa
Modified: 2015-07-06 08:06 UTC (History)
3 users (show)

See Also:


Attachments

Description Ryosuke Niwa 2015-04-22 23:45:08 UTC
Discussed here:
https://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0158.html
https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0083.html

We shouldn't support upgrading of existing elements since it leaves the corresponding DOM objects with a wrong identity.

This is also not a normal programming model. Even with ES6 modules, we don't create a dummy modules while modules are loading and later automatically replace them under the foot.
Comment 1 Domenic Denicola 2015-04-22 23:52:35 UTC
> Even with ES6 modules, we don't create a dummy modules while modules are loading and later automatically replace them under the foot.

This is exactly what we do with ES6 modules.
Comment 2 Ryosuke Niwa 2015-04-22 23:57:31 UTC
(In reply to Domenic Denicola from comment #1)
> > Even with ES6 modules, we don't create a dummy modules while modules are loading and later automatically replace them under the foot.
> 
> This is exactly what we do with ES6 modules.

How? import { myClass } from 'mymodule'; doesn't create a promise or anything. It'll just block until mymodule is loaded.
Comment 3 Domenic Denicola 2015-04-22 23:58:58 UTC
Referencing myClass will be a reference error until 'mymodule' is loaded. This normally comes up in the case of circular dependencies.
Comment 4 Ryosuke Niwa 2015-04-23 00:35:18 UTC
(In reply to Domenic Denicola from comment #3)
> Referencing myClass will be a reference error until 'mymodule' is loaded.
> This normally comes up in the case of circular dependencies.

I'm not certain what you mean by "until 'mymodule' is loaded' but the 'mymodule' will be synchronously fetched and evaluated before the following statements are executed.

e.g.
import { myClass } from 'mymodule'; // (1)
new myClass; // this line of code is never executed until (1) is done executing.

The fact we can encounter a circular dependency in (1) is an orthogonal issue. The fact of matter is that the declarative syntax for importing an ES6 module DOES synchronously block the script execution.
Comment 5 Domenic Denicola 2015-04-23 01:23:23 UTC
It is correct that (2) will not execute until (1) is done executing. But (1) simply creates a dummy myClass binding which will cause ReferenceErrors if executed before myClass's definition is evaluated. myClass's definition may or may not be evaluated by executing (1).

Here is a simple example:

// a.js
import * as bModule from './b.js';
import { b } from './b.js';

// bModule is a dummy module with no properties
// if b is referenced it will cause a ReferenceError
// console.log(b); // fails

export let a = 1;

setTimeout(() => {
  // bModule is no longer a dummy module and has a b property
  // b can be referenced without errors
  console.log(b); // works
}, 100);

////////

// b.js
import * as aModule from './a.js';
import { a } from './a.js';

export let b = 2;

////////

// entry.js
import './b.js';

Execution order is entry.js -> a.js -> b.js. Thus inside a.js we have the dummy module which later gets upgraded. In fact this happens for a.js (and entry.js) as well, but you don't observe that since you can't see them pre-upgrade.
Comment 6 Ryosuke Niwa 2015-04-23 02:09:24 UTC
Again, even in this example, files are fetched and evaluated synchronously.

But let us not derail this bug from the main topic, which is about not upgrading custom elements. Even if my statement about class wasn't accurate, the fact that upgrading existing elements is a bad idea wouldn't change.
Comment 7 Domenic Denicola 2015-04-23 02:11:11 UTC
I think it's very relevant. In a dynamic system with interdependencies, upgrading of some sort is important. We have it for ES6 modules, and it makes just as much sense for custom elements, for the same reasons.
Comment 8 Ryosuke Niwa 2015-04-23 02:42:25 UTC
(In reply to Domenic Denicola from comment #7)
> I think it's very relevant. In a dynamic system with interdependencies,
> upgrading of some sort is important. We have it for ES6 modules, and it
> makes just as much sense for custom elements, for the same reasons.

Why?
Comment 9 Hayato Ito 2015-07-06 08:06:58 UTC
Moved to https://github.com/w3c/webcomponents/issues/134