Skip to content

Commit

Permalink
Fix regression with imported css
Browse files Browse the repository at this point in the history
Fix case where `<link rel="import" type="css">` is the only styling for
an element

Fixes #4986
  • Loading branch information
dfreedm committed Dec 12, 2017
1 parent 8196483 commit 706e602
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@
// ensure all gathered styles are actually in this template.
for (let i=0; i < styles.length; i++) {
let s = styles[i];
let templateStyle = templateStyles[templateStyleIndex];
// if no styles in the template, fall back to first element child of template
let templateStyle = templateStyles.length ?
templateStyles[templateStyleIndex] : template.content.firstElementChild;
// if the style is not in this template, it's been "included" and
// we put a clone of it in the template before the style that included it
if (templateStyle !== s) {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,21 @@
</script>
</dom-module>

<dom-module id="x-only-link-style">
<link rel="import" type="css" href="styling-import1.css">
<template>
<div id="one"></div>
</template>
<script>
addEventListener('WebComponentsReady', () => {
class XOnlyLink extends Polymer.Element {
static get is() { return 'x-only-link-style'; }
}
customElements.define(XOnlyLink.is, XOnlyLink);
});
</script>
</dom-module>

<script>
(function() {
function assertComputed(element, value, property, pseudo) {
Expand Down Expand Up @@ -985,6 +1000,12 @@
assertComputed(e, '5px', 'padding-top');
});

test('elements without styles work', function() {
var e = document.createElement('x-only-link-style');
document.body.appendChild(e);
assertComputed(e.$.one, '1px');
});

});

if (window.ShadyDOM) {
Expand Down

0 comments on commit 706e602

Please sign in to comment.