(originally from https://github.com/w3c/webcomponents/issues/392, moved here)
I'm working on a library (at http://infamous.io, for now at least) in which I'm creating a set of Custom Elements for rendering a 3D scene. The library registers two elements, [<motor-scene>](https://github.com/infamous/infamous/blob/master/src/motor-html/scene.js)
and <motor-node>
. The library depends on this document.registerElement
polyfill for non-supporting browsers.
I have a small problem. Everything works fine when I use the custom elements in the <body>
of a Meteor app, but when I try doing the exact same thing with a static HTML page and the scripts manually included in the <head>
, it fails and doesn't work as expected. I'm not sure if I'm doing something wrong and don't know something about Custom Elements, or if there's a problem with the API.
To see the working demo, just
git clone git@github.com:trusktr/site.git
cd site
git checkout infamous-motor-html # it's on this branch.
npm install
meteor # meteor is really easy to install, meteor.com
# visit localhost:3000
The result looks like this, the teal and pink elements positioned as expected in 3D space:
Now, if you look in the public
folder, you'll see the static version in html-demo.html
. You can open this directly in your browser with file://
, or visit localhost:3000/html-demo.html
while running the Meteor app. I have double checked, and I believe that I am doing the same exact thing as in the Meteor version, but I simply cannot get the expected result, and it looks like this:
I'm not sure what the problem is, and why it works in the Meteor version (Meteor 1.3 compiles the code with Babel) and doesn't work in the static version (also compiled with Babel via Webpack).
I've added console.logs
to the createdCallback
, attachedCallback
, etc methods in the registerElement
calls (for example). This shows two different orderings of output in the console.
The output for the Meteor version:
The output for the static version:
Could there be a load-order problem? Are there any rules on when registerElement
should be called? I tried placing the static scripts at the end of the page, which changes the output order, but still renders the same thing (broken, not like the Meteor version).
Any ideas? Is there something about Custom Elements that I don't know? Why does the static example not appear the same as the Meteor example?
Note: I get the same inconsistent behavior between Meteor and static, when using the WebReflection/document-register-element polyfill, and when not.