Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto binding template not stamped when async import is used to load polymer #1968

Closed
ebidel opened this issue Jun 26, 2015 · 7 comments
Closed
Assignees
Labels

Comments

@ebidel
Copy link
Contributor

ebidel commented Jun 26, 2015

If one makes their main page import that loads polymer.html async, e.g. <link rel="import" href="elements.html" async>, auto binding templates on the page do not stamp their content.

@ebidel
Copy link
Contributor Author

ebidel commented Jun 26, 2015

Current workaround:

function importLoaded(e) {
  document.querySelector('template[is="dom-bind"]')._readySelf();
}
<link rel="import" href="..." async onload="importLoaded(event)">

@sorvell sorvell self-assigned this Jun 26, 2015
@sorvell sorvell added the p1 label Jun 26, 2015
@sorvell
Copy link
Contributor

sorvell commented Jun 26, 2015

It looks like this only occurs on Chrome when WebComponents polyfill (webcomponents-lite.js) is not loaded. Can you confirm?

ok: http://jsbin.com/cahuha/1/edit?html,output
not working: http://jsbin.com/wubulo/edit?html,output

@ebidel
Copy link
Contributor Author

ebidel commented Jun 26, 2015

Yep confirmed. I'm dynamically loading the polyfill based on feature detection, which means Chrome is never getting it. Confirmed your bins too.

@sorvell
Copy link
Contributor

sorvell commented Jun 26, 2015

Thanks. There is an easy fix that will get the dom-bind to stamp, but there will be some issues that are worth a bit of discussion.

The reason that dom-bind does not stamp immediately is that it's a requirement that all custom elements used inside the dom-bind are available when the template stamps. Otherwise, bindings may propagate property values to un-upgraded elements that go unseen when the element is upgraded. This is, perhaps, unlikely (a value comes out of an upgraded element and is routed into an un-upgraded one), but it can happen.

Our typical strategy is to simply wait for HTMLImports to resolve before stamping the dom-bind. However, this is not a generally knowable state when async imports are used.

We could simply not provide any help for this situation when async imports are used (always stamp if the dom-bind is created after document.readyState === 'complete'. This is the easy fix).

Alternatively, we can attempt to see if any currently existing imports are loaded and wait for them to load if not. Unfortunately, HTML Imports currently gives no way to distinguish that an import has already 404'd. In that case this strategy would fail.

Another option is simply to make users stamp the dom-bind themselves in this case. If we go with this, then a public stamp method is necessary.

@ebidel
Copy link
Contributor Author

ebidel commented Jul 7, 2015

I'd be happy with a public method for stamping. I suppose if someone is already going the async route, they're probably comfortable/interested in full control.

@sorvell
Copy link
Contributor

sorvell commented Jul 18, 2015

Closed via #2090. The dom-bind element now has a render method which can be called when using async imports.

@sorvell sorvell closed this as completed Jul 18, 2015
@Frikki
Copy link

Frikki commented Jul 19, 2015

@sorvell So instead of @ebidel’s fix:

document.querySelector('template[is="dom-bind"]')._readySelf();

we should substitute the _readySelf() with render()? Like this:

document.querySelector('template[is="dom-bind"]').render();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants