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

importHref should load imports asynchronously #3113

Closed
ebidel opened this issue Nov 30, 2015 · 8 comments
Closed

importHref should load imports asynchronously #3113

ebidel opened this issue Nov 30, 2015 · 8 comments

Comments

@ebidel
Copy link
Contributor

ebidel commented Nov 30, 2015

Polymer.Base.importHref doesn't load imports asynchronously. In apps, this can cause layout flashes as the import is added to the DOM and loads. I've witnessed this on a couple of apps were we're using importHref to dynamically load bundles, asynchronously.

Instead, loading it with the async attr take it out of rendering and solves the issue.

ebidel added a commit that referenced this issue Nov 30, 2015
@kevinpschaaf
Copy link
Member

Can you provide a repro of how the layout "flashes" when a sync import is added to the document?

It doesn't make sense that a sync import would cause fouc and that making it async would fix it, without there being some sort of underlying Chrome bug, so it's worth understanding what you're actually seeing.

@ebidel
Copy link
Contributor Author

ebidel commented Dec 1, 2015

Sure. Here are some examples.

Sync load (flash):

sync

Sync load (watch for flash after spinner stops):

codelabs_sync

Async load (no flash. elements fade in when they're upgraded):

codelabs_async

Test app (run in canary so you dont need to babel):

  1. git clone https://github.com/ebidel/polymer-experiments
  2. cd polymer-experiments/polymersummit/fouc/
  3. bower install
  4. Remove ".v" in https://github.com/ebidel/polymer-experiments/blob/master/polymersummit/fouc/binding.html#L10 to use the unvulcanized version.

Serve up binding.html. It won't produce a flash.

  1. To make it flash, change https://github.com/ebidel/polymer-experiments/blob/master/polymersummit/fouc/elements/bootstrap.html#L61 by adding false as a 2nd param to importHref. That makes it sync:

    importHref('elements/elements-no-polymer.v.html', false).then(function(link) {
    

Not sure what's going on here. It may be something with stylesheets/styles in imports getting added to the main document and causing layout/recalc styles. That's my hunch, but I haven't bee able to pinpoint it. FWIW, Both of these apps also use paper-drawer-panel.

@kevinpschaaf
Copy link
Member

Reproduced the blinking issue down to an apparent chrome bug related to async imports, filed here: https://code.google.com/p/chromium/issues/detail?id=564758

@TimvdLippe
Copy link
Contributor

@kevinpschaaf Your link results in a 403.

@ebidel
Copy link
Contributor Author

ebidel commented Dec 3, 2015

It's restricted, internal for some reason.

@kevinpschaaf
Copy link
Member

@JeremybellEU Sorry, should be unrestricted now.

@TimvdLippe
Copy link
Contributor

👍

ebidel added a commit that referenced this issue Dec 10, 2015
@ebidel
Copy link
Contributor Author

ebidel commented Dec 10, 2015

Default will be sync, but we're adding the optional 4th arg for async :)

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

No branches or pull requests

3 participants