Skip to content
Browse files

Fixes #2304: avoid trying to read style data from imports that did no…

…t load.
  • Loading branch information...
1 parent a42ca09 commit 0d1f206f6990d713546f1e27b2ce5fe5270e8fa8 @sorvell sorvell committed
Showing with 12 additions and 18 deletions.
  1. +11 −18 src/lib/style-util.html
  2. +1 −0 test/unit/styling-remote-elements.html
View
29 src/lib/style-util.html
@@ -106,13 +106,10 @@
var cssText = '';
// if element is a template, get content from its .content
var content = element.content || element;
- var sourceDoc = element.ownerDocument;
var e$ = Array.prototype.slice.call(
content.querySelectorAll(this.MODULE_STYLES_SELECTOR));
- for (var i=0, e, resolveDoc, addModule; i < e$.length; i++) {
+ for (var i=0, e; i < e$.length; i++) {
e = e$[i];
- resolveDoc = sourceDoc;
- addModule = null;
// look inside templates for elements
if (e.localName === 'template') {
cssText += this._cssFromElement(e);
@@ -120,25 +117,21 @@
// style elements inside dom-modules will apply to the main document
// we don't want this, so we remove them here.
if (e.localName === 'style') {
- addModule = e.getAttribute(this.INCLUDE_ATTR);
+ var include = e.getAttribute(this.INCLUDE_ATTR);
// get style element applied to main doc via HTMLImports polyfill
e = e.__appliedElement || e;
e.parentNode.removeChild(e);
+ cssText += this.resolveCss(e.textContent, element.ownerDocument);
+ // now support module refs on 'styling' elements
+ if (include) {
+ cssText += this.cssFromModules(include);
+ }
// it's an import, assume this is a text file of css content.
- } else {
- // TODO(sorvell): plan is to deprecate this way to get styles;
- // remember to add deprecation warning when this is done.
- e = e.import && e.import.body;
- resolveDoc = e.ownerDocument;
+ // TODO(sorvell): plan is to deprecate this way to get styles;
+ // remember to add deprecation warning when this is done.
+ } else if (e.import && e.import.body) {
+ cssText += this.resolveCss(e.import.body.textContent, e.import);
}
- // adjust paths in css.
- if (e) {
- cssText += this.resolveCss(e.textContent, resolveDoc);
- }
- }
- // now support module refs on 'styling' elements
- if (addModule) {
- cssText += this.cssFromModules(addModule);
}
}
return cssText;
View
1 test/unit/styling-remote-elements.html
@@ -10,6 +10,7 @@
}
</style>
<template>
+ <link rel="import" type="css" href="styling-remote-sheet.css">
<div id="me" class="border">border should be 10px</div>
</template>
<script>

0 comments on commit 0d1f206

Please sign in to comment.
Something went wrong with that request. Please try again.