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

custom-style: using async import fails to shim styles #2481

Closed
ebidel opened this issue Sep 25, 2015 · 10 comments
Closed

custom-style: using async import fails to shim styles #2481

ebidel opened this issue Sep 25, 2015 · 10 comments

Comments

@ebidel
Copy link
Contributor

ebidel commented Sep 25, 2015

Using paper-styles.html (where polymer.html is a sub-import) fails to apply the styling - http://jsbin.com/fujiqixaki/edit?html,output:

<link rel="import" href="https://polygit.org/polymer/components/paper-styles/color.html" async>
<style is="custom-style">
  body {
    background: var(--paper-green-500);
  }
</style>

Interestingly, using an async polymer.html on the main page WORKS - http://jsbin.com/tuxajomelo/edit?html,output:

<link rel="import" href="https://polygit.org/polymer/components/polymer/polymer.html" async>
<style is="custom-style">
  :root {
    --paper-green-500: green;
  }
  body {
    background: var(--paper-green-500);
  }
</style>
@ebidel
Copy link
Contributor Author

ebidel commented Sep 25, 2015

@sorvell wanted to verify these two upgrades happen for sync and non-async:

non-async case

  1. color.html
  2. loads polymer.html
  3. upgrades custom-style in color.html
  4. upgrades custom-style in main document

async case

  1. async color.html
  2. loads polymer
  3. upgrades custom-style in main document*
  4. upgrades custom-style in color.html

Results: In both cases, 3 and 4 are upgraded. Repo:

function logStuff(importDoc) {
  var importStyle = importDoc.import.querySelector('style');
  console.log('custom-style upgraded in color.html import:',
              importStyle.__isPolymerInstance__);

  var mainDocStyle = document.querySelector('style');
  console.log('custom-style upgraded in main doc:',
              mainDocStyle.__isPolymerInstance__);
}
</script>

<link rel="import" href="https://polygit.org/polymer/components/paper-styles/color.html"
      async onload="logStuff(this)">

<style is="custom-style">
  body {
    background: var(--paper-green-500);
    color: white;
  }
</style>

<p>Background should be green.</p>

Drop this in a page and toggle the async attr. Sync will show a green page. async will not. Note testing on a jsbin doesnt work very well. Weird timing or caching issues with it or polygit.

@ebidel
Copy link
Contributor Author

ebidel commented Sep 25, 2015

With async, the custom-style upgrades are main doc, then import. Without it, the order is import, then main doc.

@jmcgdz
Copy link

jmcgdz commented Sep 25, 2015

@ebidel

I am upgrading to 1.1.3 and seeing a similar issue with elements that are created after ready(),
like select2 selects after data is returned from an ajax call.

Does that sound like the same issue?

Also, is there a programmatic way to reapply the styles?

@ebidel
Copy link
Contributor Author

ebidel commented Sep 25, 2015

Sounds different. This is about async imports. I doubt they're using them.

select2 might not be using Polymer.dom()? For that kind of 3rd party that doesn't use Polymer's stuff, you can use scopeSubtree: #2299

@jmcgdz
Copy link

jmcgdz commented Sep 25, 2015

@ebidel Yep, that's the one. Confirmed. Thanks for the workaround

@ebidel
Copy link
Contributor Author

ebidel commented Nov 11, 2015

Related: #2522 (comment)

@valdrinkoshi
Copy link
Member

Also this one seems related: PolymerElements/iron-overlay-behavior#23

@rodrigogoncalves
Copy link

Also, is there a programmatic way to reapply the styles?

@2pha
Copy link

2pha commented Apr 26, 2016

I came across this issue today when trying to add a splash screen following the polymer starter kit performance docs

@tjsavage tjsavage added the 1.x label Sep 8, 2016
@TimvdLippe TimvdLippe self-assigned this Feb 6, 2018
@TimvdLippe
Copy link
Contributor

I am closing this issue as it suffers from the same root problem described in #2522. Please see #2522 (comment) and #2522 (comment) for more information.

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

10 participants