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(addStyles): correctly check singleton behavior when {Boolean} (options.singleton) #285

Merged
merged 1 commit into from
Dec 14, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`.
|**`transform`** |`{Function}`|`false`|Transform/Conditionally load CSS by passing a transform/condition function|
|**`insertAt`**|`{String\|Object}`|`bottom`|Inserts `<style></style>` at the given position|
|**`insertInto`**|`{String}`|`<head>`|Inserts `<style></style>` into the given position|
|**`singleton`**|`{Boolean}`|`undefined`|Reuses a single `<style></style>` element, instead of adding/removing individual elements for each required module.|
|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|
|**`convertToAbsoluteUrls`**|`{Boolean}`|`false`|Converts relative URLs to absolute urls, when source maps are enabled|

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

### `singleton`

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

> ℹ️ 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.

Expand Down
2 changes: 1 addition & 1 deletion lib/addStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = function(list, options) {

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

// By default, add <style> tags to the <head> element
if (!options.insertInto) options.insertInto = "head";
Expand Down
23 changes: 22 additions & 1 deletion test/basicTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("basic tests", function() {
}, selector);
}); // it insert into

it("singleton", function(done) {
it("singleton (true)", function(done) {
// Setup
styleLoaderOptions.singleton = true;

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

it("singleton (false)", function(done) {
// Setup
styleLoaderOptions.singleton = false;

fs.writeFileSync(
rootDir + "main.js",
[
"var a = require('./style.css');",
"var b = require('./styleTwo.css');"
].join("\n")
);

// Run
let expected = [
existingStyle,
`<style type="text/css">${requiredCss}</style><style type="text/css">${requiredCssTwo}</style>`
].join("\n");

runCompilerTest(expected, done);
}); // it singleton

it("attrs", function(done) {
// Setup
styleLoaderOptions.attrs = {id: 'style-tag-id'};
Expand Down