Workaround: Avoid byte order markers (BOM) in CSS assets - #3644
Merged
Conversation
See the original issue upstream: WordPress/gutenberg#81382 Until the fix is released in wp-scripts, prevent the unintended (and breaking) introduction of BOMs in CSS assets by modifiying the default webpack rules.
There was a problem hiding this comment.
Pull request overview
This PR adds a temporary workaround in the project’s custom webpack configuration to prevent UTF‑8 byte order marks (BOMs) from being introduced into generated CSS assets, pending an upstream fix in @wordpress/scripts.
Changes:
- Adds a
withoutSassCharset()transformation to forcesassOptions.charset = falseforsass-loaderrules to avoid BOMs in concatenated CSS output. - Regenerates built CSS assets to remove BOM bytes (no functional CSS changes intended).
- Updates build asset version hashes (
*.asset.php) to reflect regenerated artifacts.
Reviewed changes
Copilot reviewed 5 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| webpack.config.js | Adds a webpack rule transform to disable Sass charset output as a BOM workaround. |
| build/following/style-index.css | Regenerated built CSS to remove BOM bytes. |
| build/following/style-index-rtl.css | Regenerated built CSS to remove BOM bytes. |
| build/following/index.asset.php | Updates build hash due to regenerated assets. |
| build/followers/style-index.css | Regenerated built CSS to remove BOM bytes. |
| build/followers/style-index-rtl.css | Regenerated built CSS to remove BOM bytes. |
| build/followers/index.asset.php | Updates build hash due to regenerated assets. |
| build/dashboard-stats/style-index.css | Regenerated built CSS to remove BOM bytes. |
| build/dashboard-stats/style-index-rtl.css | Regenerated built CSS to remove BOM bytes. |
| build/dashboard-stats/index.asset.php | Updates build hash due to regenerated assets. |
| build/app/routes/feed/style-content.css | Regenerated built CSS to remove BOM bytes. |
| build/app/routes/feed/content.asset.php | Updates build hash due to regenerated assets. |
Files not reviewed (6)
- build/dashboard-stats/style-index-rtl.css: Generated file
- build/dashboard-stats/style-index.css: Generated file
- build/followers/style-index-rtl.css: Generated file
- build/followers/style-index.css: Generated file
- build/following/style-index-rtl.css: Generated file
- build/following/style-index.css: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+148
to
+170
| const withoutSassCharset = ( rules ) => | ||
| rules.map( ( rule ) => { | ||
| if ( ! Array.isArray( rule?.use ) ) { | ||
| return rule; | ||
| } | ||
|
|
||
| return { | ||
| ...rule, | ||
| use: rule.use.map( ( item ) => { | ||
| if ( typeof item !== 'object' || ! item?.loader?.includes( 'sass-loader' ) ) { | ||
| return item; | ||
| } | ||
|
|
||
| return { | ||
| ...item, | ||
| options: { | ||
| ...item.options, | ||
| sassOptions: { ...item.options?.sassOptions, charset: false }, | ||
| }, | ||
| }; | ||
| } ), | ||
| }; | ||
| } ); |
Member
Author
There was a problem hiding this comment.
I think this recommendation is overkill, we just want a workaround targeting the setup in Gutenberg (wp-scripts) and the setup here.
arcangelini
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes:
See the original issue upstream:
Until the fix is released in wp-scripts, prevent the unintended (and breaking) introduction of BOMs in CSS assets by modifiying the default webpack rules.
Verifying the build assets
Other than the change in
webpack.config.js, it's impossible to verify this PR's CSS changes, since BOMs aren't represented.I wanted to be sure that my fix was good, so I wrote this shell script:
Pass it the two revisions to compare, e.g.
Verify that there are only BOM changes reported, nothing else.