Skip to content
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
4 changes: 4 additions & 0 deletions packages/wp-build/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- Derive `data-wp-hash` from the transformed CSS instead of the raw source to prevent style mismatches when multiple build pipelines process the same source file ([#76743](https://github.com/WordPress/gutenberg/pull/76743)).

## 0.10.0 (2026-03-18)

### Breaking Changes
Expand Down
13 changes: 7 additions & 6 deletions packages/wp-build/lib/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ function getSassOptions( workingDir ) {

function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
return async function styleType( cssText, _dirname, filePath ) {
// Always hash the untransformed code.
const hash = createHash( 'sha1' )
.update( cssText )
.digest( 'hex' )
.slice( 0, 10 );

let moduleExports = null;

// Transform the code: token fallbacks, CSS modules and minification.
Expand All @@ -214,6 +208,13 @@ function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
map: false,
} );

// Hash the transformed CSS so that the dedup key reflects the actual
// injected content, including mangled CSS module class names.
const hash = createHash( 'sha1' )
.update( css )
.digest( 'hex' )
.slice( 0, 10 );

let cssModule = `if (typeof document !== 'undefined' && process.env.NODE_ENV !== 'test' && !document.head.querySelector("style[data-wp-hash='${ hash }']")) {
const style = document.createElement("style");
style.setAttribute("data-wp-hash", "${ hash }");
Expand Down
Loading