GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Preserve the BOM when stringifying by hdimer · Pull Request #2119 · postcss/postcss

Conversation

@hdimer

@hdimer hdimer commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

PostCSS aims for byte-to-byte equal output, but the stringifier drops a leading byte order mark:

postcss.parse('a{color:red}').toString() // => 'a{color:red}', BOM lost

The BOM is already detected (Input#hasBOM), but it was never re-emitted, so the round-trip isn't lossless. The bom.css parser-test fixture was excluded from the stringify round-trip test for this reason (if (name === 'bom.css') return).

This emits the BOM in Stringifier#root when the source had one, and removes that skip so the bom.css round-trip is now covered. A programmatic root with no source emits no BOM, and non-BOM input is unchanged.

Disclosure: written with AI assistance (Claude Code); I reviewed it and verified against the full suite (unit, eslint, check-dts, size-limit all pass, incl. the newly re-enabled test).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hdimer
Preserve the BOM when stringifying
22cb61b
PostCSS aims for byte-to-byte equal output, but the stringifier dropped a
leading byte order mark: `parse('a{}').toString()` returned `a{}`. The
BOM is already detected (`Input#hasBOM`) but was never re-emitted, so the
`bom.css` round-trip test had to be skipped.

Emit the BOM in `Stringifier#root` when the source had one, and re-enable the
previously skipped test.
@ai
ai merged commit 9a114f6 into postcss:main Jul 28, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Jul 28, 2026

Copy link
Copy Markdown
Member

Thanks. Nice idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Jul 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Released in 8.5.24.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@blankse blankse mentioned this pull request Jul 29, 2026
Leading BOM from a loader-generated module survives into the middle of concatenated CSS (postcss 8.5.24) webpack/css-loader#1678
Closed
@terrymun terrymun mentioned this pull request Jul 29, 2026
Postcss 8.5.24 breaks @layer at rule #2122
Closed
@ShGKme ShGKme mentioned this pull request Jul 30, 2026
fix: strip BOM before process via PostCSS for 8.5.24 webpack/css-loader#1679
Closed
@claude claude Bot mentioned this pull request Aug 1, 2026
chore(deps-dev): bump postcss from 8.5.22 to 8.5.25 dimagi/open-chat-studio#4045
Merged
@ShGKme ShGKme mentioned this pull request Aug 4, 2026
fix: workaround for broken styles by BOM chars with postcss >=8.5.24 with mini-css-extract-plugin nextcloud-libraries/webpack-vue-config#798
Merged
1 task
@UncleJart

UncleJart commented Aug 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Interesting why BOM was stripped before? Because now this change breaks application production builds where SASS is in chain. Sass by default has charset: true option enabled and in case SCSS file has non-ASCII it adds at the top of the file @charset UTF-8; string which is been replaced with BOM when source is been compressed in production mode. Our app injects styles inline into page markdown dynamically when they are used via isomorphic-style-loader. Previously BOM was stripped and everything worked OK, but after this change BOM is been preserved and all major browsers just ignore the first rule of the compiled CSS causing styling breakages. So the question is what is the right behavior then, should it be treated as lib issue or not? Maybe BOM was stripped for this reason? Maybe it is better to introduce an option in configuration for BOM to be stripped/kept?
image

We had to downgrade to v 8.5.23 for now to fix this.

@ai What are your thoughts?

khomyakdi and mfranzke reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Aug 5, 2026

Copy link
Copy Markdown
Member

Interesting why BOM was stripped before?

It was a mistake (we forgot about it).

BOM is a well expected symbol. It is a big issue of the parser if it can't process it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@UncleJart

UncleJart commented Aug 5, 2026

Copy link
Copy Markdown

So you want to say that this is browsers (Chrome, Firefox, ...) bug that they do not parse BOM properly in inline styles?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Aug 5, 2026

Copy link
Copy Markdown
Member

No, BOM should be only in the begging of the file.

It is bug on inliner tool to not remove BOM in this case.

UncleJart reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Aug 10, 2026
[@wordpress/scripts] postcss 8.5.24 can introduce a UTF-8 BOM in the middle of extracted CSS WordPress/gutenberg#81382
Closed
Scripts: Prevent a UTF-8 BOM in the middle of extracted CSS WordPress/gutenberg#81383
Merged
@arronKler arronKler mentioned this pull request Aug 14, 2026
Do not emit multiple UTF-8 BOM markers #2136
Open
@alexander-akait alexander-akait mentioned this pull request Aug 27, 2026
fix: strip BOM before processing with postcss webpack/css-loader#1684
Merged
hanzo-dev pushed a commit to hanzoai/postcss that referenced this pull request Sep 9, 2026
@hdimer
Preserve the BOM when stringifying (postcss#2119)
05a9353
PostCSS aims for byte-to-byte equal output, but the stringifier dropped a
leading byte order mark: `parse('a{}').toString()` returned `a{}`. The
BOM is already detected (`Input#hasBOM`) but was never re-emitted, so the
`bom.css` round-trip test had to be skipped.

Emit the BOM in `Stringifier#root` when the source had one, and re-enable the
previously skipped test.
@wahidrizka wahidrizka mentioned this pull request Sep 15, 2026
Terminate a custom property after a free semicolon before a comment #2158
Merged
@anvit anvit mentioned this pull request Sep 16, 2026
Problem: Custom themes extending arDominionB5Plugin missing Bootstrap CSS variables in 2.10.2 artefactual/atom#2427
Closed
@ggdouglas ggdouglas mentioned this pull request Sep 22, 2026
[docs] Prevent BOM from corrupting production CSS palantir/blueprint#8272
Merged
@mtrezza mtrezza mentioned this pull request Sep 24, 2026
refactor: Bump postcss from 8.5.19 to 8.5.28 and css-loader from 7.1.4 to 7.1.5 parse-community/parse-dashboard#3463
Merged
This was referenced Oct 22, 2026
[Historical PR] deps(npm): bump postcss from 8.5.23 to 8.5.25 in /web/client rennerdo30/bifrost-proxy#235
Closed
[Historical PR] deps(npm): bump postcss from 8.5.23 to 8.5.25 in /web/server rennerdo30/bifrost-proxy#236
Closed
@macgyver macgyver mentioned this pull request Oct 23, 2026
Inlined CSS breaks when a stylesheet starts with a BOM clay/amphora-html#110
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@hdimer @ai @UncleJart
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.