fix: strip BOM before processing with postcss - #1684
Merged
Conversation
postcss stripped a leading BOM until 8.5.24 and preserves it since, so a BOM added by an earlier loader (sass-loader with `charset: true`) survived into the module and landed mid-file once stylesheets were concatenated, silently dropping the rule after it. Strip it for both inputs postcss accepts: the string, and the `Root` a previous loader hands over as `meta.ast`, where the BOM lives on `source.input.hasBOM` rather than in the tree.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1684 +/- ##
==========================================
+ Coverage 96.25% 96.28% +0.02%
==========================================
Files 10 10
Lines 1201 1210 +9
Branches 463 468 +5
==========================================
+ Hits 1156 1165 +9
Misses 40 40
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Fixes #1678. postcss stripped a leading BOM until 8.5.24 and preserves it since, so a BOM added by an earlier loader (
sass-loaderwithcharset: true, its production default) survived into the module and landed mid-file once stylesheets were concatenated, silently dropping the rule after it.This builds on @ShGKme's #1679 and credits that analysis; it differs in one respect.
contentis not always a string — when a previous loader hands over its AST viameta.ast,contentis a postcssRoot, andcharCodeAton it throwsTypeError: content.charCodeAt is not a function(8 existing tests fail that way). So the strip is applied to both inputs postcss accepts: the string, and theRoot, where the BOM lives onsource.input.hasBOMrather than in the tree. Thesass-loader→postcss-loader→css-loaderchain takes that second path.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes — two cases in
test/loader.test.jswith fixtures intest/fixtures/modules/issue-1678/, one per input path. Both were confirmed to fail without their half of the fix, and the whole suite passes on postcss 8.5.5 (the lockfile version) and on 8.5.26, so they do not depend on which patch is installed.Does this PR introduce a breaking change?
No — it restores the output postcss produced before 8.5.24.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Yes — Claude Code wrote the tests first and confirmed each fails without the corresponding branch of the fix, found the
Rootcase by running the existing suite against postcss 8.5.26, and verified the suite on both postcss versions. Reviewed and edited by me before pushing.Generated by Claude Code