Skip to content
Closed
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- `<PropertyValuePair />`
- fix description and story to point out that `PropertyValueList` need always to be used as wrapper
- BOM issue on compressed stylesheet
- first rule `selector` becomes `BOM:selector` that is valid but will never apply
- we fixed this problem by adding a dummy rule as first rule

### Deprecated

Expand Down
28 changes: 28 additions & 0 deletions src/_bom-workaround.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.bom-problem-workaround-dummy-rule {
/**
* This is a workaround to prevent the loss of the first rule of our compressed CSS.
*
* Sass emits a BOM instead of a `@charset` rule when it creates a compressed
* stylesheet that contains non-ASCII characters.
* Postcss preserves that BOM since v8.5.24, before that it silently dropped it.
* Css-loader does not remove it, although it inlines the CSS into a JS string that
* style-loader writes into a `<style>` element -- there the BOM is not a byte order
* mark anymore, just a stray character. Upstream considers this a css-loader issue,
*
* `U+FEFF` is a valid ident code point in CSS, so the browser reads it as a type
* selector and prepends it to the first selector: `:root` becomes `<U+FEFF>:root`.
* That selector is valid but matches no element, so the first rule never applies.
*
* Alternatively sass-loader could be configured with `charset: false`, but we prefer
* to keep the charset information in the stylesheets we ship, and is also not
* recommended to do so.
*
* @see https://github.com/postcss/postcss/pull/2119
* @see https://github.com/postcss/postcss/issues/2133
*
* IMPORTANT: this only works as long as it is the FIRST import in `src/index.scss`,
* so that this dummy rule is the first rule of the compiled output and absorbs the BOM.
*/

--dummy-property: "none";
}
2 changes: 2 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "./bom-workaround";

// == library prefix for variables and selectors ===============================

@import "./configuration/libprefix";
Expand Down
Loading