Skip to content

Commit

Permalink
Merge pull request #4991 from Polymer/fix-style-processing-only-link
Browse files Browse the repository at this point in the history
Fix regression with imported css
  • Loading branch information
dfreedm authored Dec 13, 2017
2 parents 81add63 + 2d6b468 commit f618af4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,21 @@
* @private
*/
function processElementStyles(klass, template, is, baseURI) {
const styles = Polymer.StyleGather.stylesFromModuleImports(is).concat(
Polymer.StyleGather.stylesFromTemplate(template));
const templateStyles = template.content.querySelectorAll('style');
const stylesWithImports = Polymer.StyleGather.stylesFromTemplate(template);
// insert styles from <link rel="import" type="css"> at the top of the template
const linkedStyles = Polymer.StyleGather.stylesFromModuleImports(is);
const firstTemplateChild = template.content.firstElementChild;
for (let idx = 0; idx < linkedStyles.length; idx++) {
let s = linkedStyles[idx];
s.textContent = klass._processStyleText(s.textContent, baseURI);
template.content.insertBefore(s, firstTemplateChild);
}
// keep track of the last "concrete" style in the template we have encountered
let templateStyleIndex = 0;
// ensure all gathered styles are actually in this template.
for (let i=0; i < styles.length; i++) {
let s = styles[i];
for (let i = 0; i < stylesWithImports.length; i++) {
let s = stylesWithImports[i];
let templateStyle = templateStyles[templateStyleIndex];
// 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
Expand Down
13 changes: 13 additions & 0 deletions test/unit/styling-import-host.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
:host {
display: block;
border: 1px solid black;
}
13 changes: 13 additions & 0 deletions test/unit/styling-import-host2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
:host {
display: block;
border: 2px solid black;
}
20 changes: 20 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,20 @@
</script>
</dom-module>

<dom-module id="x-only-link-style">
<link rel="import" type="css" href="styling-import-host.css">
<link rel="import" type="css" href="styling-import-host2.css">
<template></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 +999,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, '2px');
});

});

if (window.ShadyDOM) {
Expand Down

0 comments on commit f618af4

Please sign in to comment.