Skip to content

Commit 706e602

Browse files
committed
Fix regression with imported css
Fix case where `<link rel="import" type="css">` is the only styling for an element Fixes #4986
1 parent 8196483 commit 706e602

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/mixins/element-mixin.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@
255255
// ensure all gathered styles are actually in this template.
256256
for (let i=0; i < styles.length; i++) {
257257
let s = styles[i];
258-
let templateStyle = templateStyles[templateStyleIndex];
258+
// if no styles in the template, fall back to first element child of template
259+
let templateStyle = templateStyles.length ?
260+
templateStyles[templateStyleIndex] : template.content.firstElementChild;
259261
// if the style is not in this template, it's been "included" and
260262
// we put a clone of it in the template before the style that included it
261263
if (templateStyle !== s) {

test/unit/styling-scoped.html

+21
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,21 @@
715715
</script>
716716
</dom-module>
717717

718+
<dom-module id="x-only-link-style">
719+
<link rel="import" type="css" href="styling-import1.css">
720+
<template>
721+
<div id="one"></div>
722+
</template>
723+
<script>
724+
addEventListener('WebComponentsReady', () => {
725+
class XOnlyLink extends Polymer.Element {
726+
static get is() { return 'x-only-link-style'; }
727+
}
728+
customElements.define(XOnlyLink.is, XOnlyLink);
729+
});
730+
</script>
731+
</dom-module>
732+
718733
<script>
719734
(function() {
720735
function assertComputed(element, value, property, pseudo) {
@@ -985,6 +1000,12 @@
9851000
assertComputed(e, '5px', 'padding-top');
9861001
});
9871002

1003+
test('elements without styles work', function() {
1004+
var e = document.createElement('x-only-link-style');
1005+
document.body.appendChild(e);
1006+
assertComputed(e.$.one, '1px');
1007+
});
1008+
9881009
});
9891010

9901011
if (window.ShadyDOM) {

0 commit comments

Comments
 (0)