Skip to content

Commit

Permalink
Deduplicate style includes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Mar 16, 2018
1 parent 4629933 commit acfef71
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/style-gather.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
// other dom-modules that contain styling
let include = e.getAttribute(INCLUDE_ATTR);
if (include) {
styles.push(...this.stylesFromModules(include));
styles.push(...new Set(this.stylesFromModules(include)));
}
if (baseURI) {
e.textContent = Polymer.ResolveUrl.resolveCss(e.textContent, baseURI);
Expand Down
50 changes: 50 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,37 @@
</script>
</dom-module>

<dom-module id="double-shared-style">
<template>
<style>
.double-shared-style {
color: green;
}
</style>
</template>
</dom-module>

<dom-module id="importing-double-shared-style">
<template>
<style include="double-shared-style">
</style>
</template>
</dom-module>

<dom-module id="double-shared-styling-element">
<template>
<style include="importing-double-shared-style double-shared-style"></style>
</template>
<script>
addEventListener('WebComponentsReady', () => {
class DoubleSharedStylingElement extends Polymer.Element {
static get is() { return 'double-shared-styling-element'; }
}
customElements.define(DoubleSharedStylingElement.is, DoubleSharedStylingElement);
});
</script>
</dom-module>

<script>
(function() {
function assertComputed(element, value, property, pseudo) {
Expand Down Expand Up @@ -1012,6 +1043,25 @@

});

suite('double including style sheets', function() {
let el;

setup(function() {
el = document.createElement('double-shared-styling-element');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('only includes style modules once', function() {
assert.equal(el.shadowRoot.querySelector('style').textContent, `.double-shared-style {
color: green;
}`, 'There should be only one class selector in this style element');
});
});

if (window.ShadyDOM) {

suite('scoped-styling-shady-only', function() {
Expand Down

0 comments on commit acfef71

Please sign in to comment.