Skip to content

Commit 0d1f206

Browse files
author
Steven Orvell
committed
Fixes #2304: avoid trying to read style data from imports that did not load.
1 parent a42ca09 commit 0d1f206

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/lib/style-util.html

+11-18
Original file line numberDiff line numberDiff line change
@@ -106,39 +106,32 @@
106106
var cssText = '';
107107
// if element is a template, get content from its .content
108108
var content = element.content || element;
109-
var sourceDoc = element.ownerDocument;
110109
var e$ = Array.prototype.slice.call(
111110
content.querySelectorAll(this.MODULE_STYLES_SELECTOR));
112-
for (var i=0, e, resolveDoc, addModule; i < e$.length; i++) {
111+
for (var i=0, e; i < e$.length; i++) {
113112
e = e$[i];
114-
resolveDoc = sourceDoc;
115-
addModule = null;
116113
// look inside templates for elements
117114
if (e.localName === 'template') {
118115
cssText += this._cssFromElement(e);
119116
} else {
120117
// style elements inside dom-modules will apply to the main document
121118
// we don't want this, so we remove them here.
122119
if (e.localName === 'style') {
123-
addModule = e.getAttribute(this.INCLUDE_ATTR);
120+
var include = e.getAttribute(this.INCLUDE_ATTR);
124121
// get style element applied to main doc via HTMLImports polyfill
125122
e = e.__appliedElement || e;
126123
e.parentNode.removeChild(e);
124+
cssText += this.resolveCss(e.textContent, element.ownerDocument);
125+
// now support module refs on 'styling' elements
126+
if (include) {
127+
cssText += this.cssFromModules(include);
128+
}
127129
// it's an import, assume this is a text file of css content.
128-
} else {
129-
// TODO(sorvell): plan is to deprecate this way to get styles;
130-
// remember to add deprecation warning when this is done.
131-
e = e.import && e.import.body;
132-
resolveDoc = e.ownerDocument;
130+
// TODO(sorvell): plan is to deprecate this way to get styles;
131+
// remember to add deprecation warning when this is done.
132+
} else if (e.import && e.import.body) {
133+
cssText += this.resolveCss(e.import.body.textContent, e.import);
133134
}
134-
// adjust paths in css.
135-
if (e) {
136-
cssText += this.resolveCss(e.textContent, resolveDoc);
137-
}
138-
}
139-
// now support module refs on 'styling' elements
140-
if (addModule) {
141-
cssText += this.cssFromModules(addModule);
142135
}
143136
}
144137
return cssText;

test/unit/styling-remote-elements.html

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
</style>
1212
<template>
13+
<link rel="import" type="css" href="styling-remote-sheet.css">
1314
<div id="me" class="border">border should be 10px</div>
1415
</template>
1516
<script>

0 commit comments

Comments
 (0)