Skip to content

Commit 2bfc93e

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
fix(addStyles): correctly check singleton behavior when {Boolean} (options.singleton) (#285)
1 parent 57c457d commit 2bfc93e

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`.
140140
|**`transform`** |`{Function}`|`false`|Transform/Conditionally load CSS by passing a transform/condition function|
141141
|**`insertAt`**|`{String\|Object}`|`bottom`|Inserts `<style></style>` at the given position|
142142
|**`insertInto`**|`{String}`|`<head>`|Inserts `<style></style>` into the given position|
143+
|**`singleton`**|`{Boolean}`|`undefined`|Reuses a single `<style></style>` element, instead of adding/removing individual elements for each required module.|
143144
|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
144145
|**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled|
145146

@@ -331,7 +332,7 @@ You can also insert the styles into a [ShadowRoot](https://developer.mozilla.org
331332

332333
### `singleton`
333334

334-
If defined, the style-loader will reuse a single `<style>` element, instead of adding/removing individual elements for each required module.
335+
If defined, the style-loader will reuse a single `<style></style>` element, instead of adding/removing individual elements for each required module.
335336

336337
> ℹ️ This option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton option.
337338

lib/addStyles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = function(list, options) {
6464

6565
// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
6666
// tags it will allow on a page
67-
if (!options.singleton) options.singleton = isOldIE();
67+
if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
6868

6969
// By default, add <style> tags to the <head> element
7070
if (!options.insertInto) options.insertInto = "head";

test/basicTest.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe("basic tests", function() {
140140
}, selector);
141141
}); // it insert into
142142

143-
it("singleton", function(done) {
143+
it("singleton (true)", function(done) {
144144
// Setup
145145
styleLoaderOptions.singleton = true;
146146

@@ -161,6 +161,27 @@ describe("basic tests", function() {
161161
runCompilerTest(expected, done);
162162
}); // it singleton
163163

164+
it("singleton (false)", function(done) {
165+
// Setup
166+
styleLoaderOptions.singleton = false;
167+
168+
fs.writeFileSync(
169+
rootDir + "main.js",
170+
[
171+
"var a = require('./style.css');",
172+
"var b = require('./styleTwo.css');"
173+
].join("\n")
174+
);
175+
176+
// Run
177+
let expected = [
178+
existingStyle,
179+
`<style type="text/css">${requiredCss}</style><style type="text/css">${requiredCssTwo}</style>`
180+
].join("\n");
181+
182+
runCompilerTest(expected, done);
183+
}); // it singleton
184+
164185
it("attrs", function(done) {
165186
// Setup
166187
styleLoaderOptions.attrs = {id: 'style-tag-id'};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy