Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression with imported css #4991

Merged
merged 2 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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