Skip to content

wp-build: Derive CSS module class names from each stylesheet's CSS - #85900

Merged
mirka merged 6 commits into
trunkfrom
fix/wp-build-css-module-class-names-from-css
Oct 30, 2026
Merged

mirka merged 6 commits into
trunkfrom
fix/wp-build-css-module-class-names-from-css

Conversation

@mirka

@mirka mirka commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

What?

Fixes #85896

This PR changes how @wordpress/build generates CSS module class names. Each name now changes whenever the CSS that defines it changes. Previously, names depended only on the file path and the local class name.

Why?

When two copies of a package are loaded, for example @wordpress/ui in WordPress Core and an older copy bundled in a plugin, their class names are the same even where their CSS differs. Both style tags are injected, and each one styles the other copy's elements. The issue shows this mix of 0.24.0 and 0.25.0 Tabs styles.

Why the class names did not depend on the CSS

compile-inline-style.mjs passes generateScopedName: '[contenthash]__[local]' to postcss-modules. Despite the [contenthash] placeholder, postcss-modules hands a string pattern to generic-names, and generic-names hashes hashPrefix + path.relative( process.cwd(), filepath ) + "\0" + localName. The CSS is never part of that hash, so the Tabs tab class is a5fd8814f195aa5e__tab in @wordpress/ui 0.22.0, 0.24.0 and 0.25.0 alike. This has been the case since #74651 introduced the pattern, and the earlier [name]__[local]__[hash:base64:5] pattern was also path-based.

Since #76743, the data-wp-hash deduplication key is a hash of the transformed CSS. So when two copies of a package differ in a stylesheet, their keys differ but their class names do not.

Mini retrospective — What went wrong?

I wanted to figure out where we went wrong here, because at least I personally assumed that it was already hashing the style content.

  1. The placeholder name was trusted. [contenthash] was taken to mean a hash of the stylesheet, but loader-utils treats [hash] and [contenthash] the same, and generic-names only gives it the path and the local name. Nothing checked what it actually hashed.
  2. A stated rule was applied to only half the system. wp-build: Hash transformed CSS for data-wp-hash dedupe key #76743 said two stylesheets should share a hash only when they have the same class names and the same styles. It applied that rule to the data-wp-hash dedup key, but nobody checked whether the class names followed it too.
  3. No test could catch it. Within any single build, the class names and the CSS always match. The bug only shows up when two builds with different CSS for the same component load on one page, and nothing tested that case. The new tests check the rule directly: changing a file's CSS, or a file it composes from, renames the affected classes.

How?

generateScopedName is now a function that hashes the file path, the CSS of the file that defines the class, and the local class name. Classes reached through composes are hashed with the CSS of their own file, and the design token fallbacks are part of the hashed CSS. Two files with the same path and identical CSS still produce identical names, so unchanged components in two copies of a package still share their class names and style tags.

Implementation details

postcss-modules-scope calls the function as generateScopedName( name, filename, css ), where css is the source of the file that defines the class. That includes files reached through composes, which postcss-modules compiles with the same generator and inlines into the importing file's output. The name is a hash of three values, followed by __<local>:

  1. The file path relative to process.cwd(), with forward slashes, which is the same root generic-names used. Output does not depend on the checkout location or the operating system.
  2. That file's CSS after the plugins that run before postcss-modules, which is currently the design token fallback plugin.
  3. The local class name.

A name that would start with a digit gets a _ prefix, like before.

The design token fallbacks are applied after the source is read, so the css argument does not contain them. The generator runs the preceding plugins on that source before hashing it, so a changed fallback value renames the classes in the files that use it. The fallback values come from the installed @wordpress/theme (design-tokens.js, loaded through @wordpress/theme-build-tools). Hashing them as a separate salt would rename every class whenever any token changed, and the salt would have to be read differently on wp/7.2, where the plugin is loaded from @wordpress/theme directly. Reusing the plugin list avoids both problems. The processed source is cached per file, so each stylesheet is processed once more per build.

Why not hashPrefix

The issue proposes running the token fallbacks in a separate PostCSS pass and passing a hash of the result as hashPrefix. That has two problems:

  1. @wordpress/ui composes classes across files, for example composes: header from "../utils/css/overlay-chrome.module.css" in Dialog, Drawer and AlertDialog, and composes: dropdown-motion from "../utils/css/dropdown-motion.module.css" in Menu. The composed classes are named by the same generator and would use the importing file's hashPrefix. If only overlay-chrome.module.css changed, those classes in Dialog would keep their old names with the new CSS, which is the same collision.
  2. When postcss-modules compiles a file reached through composes, it re-runs only the plugins that come before it in the same processor. A separate fallback pass would drop the fallbacks from the inlined composed CSS.

Limitations

This change only affects copies of these packages that are built after it. Copies built before it, including those in WordPress and plugin versions that are already released, keep their path-based class names.

  1. A copy built after this change shares no class names with a copy built before it. The two no longer style each other's elements. As a trade-off, a stylesheet that is identical in both copies is injected once per copy instead of once in total.
  2. Copies built before this change can still collide with each other, for example when two plugins bundle different older versions of @wordpress/ui. This is fixed only when those plugins update to versions built after this change.
  3. Plugins that compile their own CSS modules with @wordpress/build get this change only when they update @wordpress/build and rebuild.

Testing Instructions

  1. Run npm run build and check the class names in packages/ui/build-module/tabs/tab.mjs. The tab class is no longer a5fd8814f195aa5e__tab, which is its name in the published @wordpress/ui@0.25.0.
  2. Run npm run build again and confirm that the class names do not change.
  3. Change a declaration in packages/ui/src/utils/css/overlay-chrome.module.css and rebuild. In packages/ui/build-module/dialog/header.mjs, the classes composed from that file (__header, __title, __content and __footer) get new names, and the classes defined in dialog/style.module.css keep theirs.
  4. Render Dialog, Drawer, AlertDialog and Menu from the built package, open each one, and compare it with a build from trunk. The composed header, footer, title, content and dropdown motion styles still apply, and the computed styles match. Storybook compiles @wordpress/ui from source with Vite's CSS module support, so it does not exercise this code path.

✍️ Dev note for WP 7.2

Update bundled @wordpress/* packages and @wordpress/build to fix CSS module class name collisions

If your plugin bundles @wordpress/* packages that use CSS modules, or compiles its own CSS modules with @wordpress/build, take these steps before WordPress 7.2:

  1. Update bundled packages that use CSS modules to versions built with the fix, and release a new version of your plugin. The minimum versions with the fix are @wordpress/ui 0.26.0, @wordpress/dataviews 22.0.0, @wordpress/admin-ui 3.1.0, and @wordpress/grid 0.11.0. If your plugin bundles @wordpress/components instead of using the wp-components script, update it to 44.0.0 or later.
  2. If your plugin compiles its own CSS modules with @wordpress/build, update to 0.27.0 or later and rebuild.

The problem

Some @wordpress/* packages are bundled into each plugin that uses them instead of being loaded once as shared scripts. A bug in @wordpress/build, the tool that compiles these packages, made bundled copies of a package at different versions share CSS module class names. Class names were meant to change whenever the CSS that defines them changes, so that each copy's styles apply only to its own components. Instead, they depended only on the file path and the class name. When two copies with different styles were loaded on one page, for example one in WordPress and another bundled in a plugin, each copy's styles also applied to the other copy's components. The result could match neither version, such as a focus ring appearing on every hovered tab (#85896).

This affects every version of these packages published before the fix.

What changes in WordPress 7.2

Starting with WordPress 7.2, class names change whenever the CSS that defines them changes (#85900). Two copies share class names only when their CSS is identical, so a copy with different styles no longer affects the other.

The packages that ship with WordPress 7.2 are built this way. A copy your plugin bundled from an earlier version no longer collides with them. However, two copies built before the change can still collide with each other, for example when two plugins on the same site bundle different older versions of @wordpress/ui.

`generateScopedName: '[contenthash]__[local]'` was hashed by `generic-names`
from the file path and local name only, so class names stayed the same across
package versions while the CSS behind them changed. Two bundled copies of a
package then applied their styles to each other's elements.

Hash the relative file path, the CSS of the file that defines each class, and
the local name instead. The CSS comes from `postcss-modules-scope`, which also
covers files reached through `composes`, and is run through the plugins that
precede `postcss-modules` first so that a changed token fallback also renames
the affected classes.

Fixes #85896.
@mirka mirka added [Type] Build Tooling Issues or PRs related to build tooling [Package] wp-build /packages/wp-build Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Oct 29, 2026
@mirka mirka self-assigned this Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Nikschavan <nikschavan@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +68 B (0%)

Total Size: 8.57 MB

📦 View Changed
Filename Size Change
build/modules/boot/index.min.js 51.3 kB -19 B (-0.04%)
build/modules/core-fields/attachment.min.js 39.3 kB +7 B (+0.02%)
build/modules/core-fields/page.min.js 7.07 kB +5 B (+0.07%)
build/modules/core-fields/post_type_supports.min.js 73.4 kB +9 B (+0.01%)
build/modules/core-fields/wp_block.min.js 34.6 kB +8 B (+0.02%)
build/modules/core-fields/wp_template_part.min.js 34.4 kB +1 B (0%)
build/modules/core-fields/wp_template.min.js 7.41 kB +10 B (+0.14%)
build/modules/workflow/index.min.js 41 kB +7 B (+0.02%)
build/scripts/block-directory/index.min.js 42.7 kB +2 B (0%)
build/scripts/block-editor/index.min.js 542 kB +38 B (+0.01%)
build/scripts/block-library/index.min.js 402 kB -49 B (-0.01%)
build/scripts/components/index.min.js 329 kB -14 B (0%)
build/scripts/customize-widgets/index.min.js 22.8 kB +2 B (+0.01%)
build/scripts/edit-post/index.min.js 45.2 kB -3 B (-0.01%)
build/scripts/edit-site/index.min.js 376 kB +30 B (+0.01%)
build/scripts/edit-widgets/index.min.js 29 kB +7 B (+0.02%)
build/scripts/editor/index.min.js 559 kB +3 B (0%)
build/scripts/format-library/index.min.js 79.2 kB -9 B (-0.01%)
build/scripts/media-utils/index.min.js 232 kB +23 B (+0.01%)
build/scripts/patterns/index.min.js 12.9 kB +11 B (+0.09%)
build/scripts/theme/index.min.js 27 kB -2 B (-0.01%)
build/scripts/widgets/index.min.js 64.1 kB +1 B (0%)

53d35e3 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric a38f673 trunk % Change
timeToFirstByte 54.7 ms +14.99% -3.11% 55.15 ms +8.98% -3.35% -0.82%
largestContentfulPaint 88 ms +13.64% -0% 92 ms +0% -4.35% -4.35%
lcpMinusTtfb 35.05 ms +10.27% -6.13% 33.3 ms +17.57% -3.15% 5.26%
wpBeforeTemplate 28.54 ms +12.37% -1.79% 28.76 ms +14.01% -2.09% -0.76%
wpTemplate 22.17 ms +3.83% -3.79% 22.19 ms +5.41% -5.14% -0.09%
wpTotal 51.14 ms +14.47% -3.72% 51.5 ms +9.34% -4.04% -0.7%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric a38f673 trunk % Change
timeToFirstByte 45.45 ms +6.82% -2.2% 45.2 ms +5.53% -1.22% 0.55%
largestContentfulPaint 100 ms +2% -4% 98 ms +2.04% -2.04% 2.04%
lcpMinusTtfb 52.3 ms +3.35% -1.34% 51.4 ms +4.67% -0.58% 1.75%
wpBeforeTemplate 25.98 ms +4.77% -0.73% 25.87 ms +8% -1.55% 0.43%
wpTemplate 16.52 ms +3.63% -4.84% 16.43 ms +2.74% -3.59% 0.55%
wpTotal 42.54 ms +6.72% -2.63% 42.14 ms +5.96% -1.31% 0.95%
wpMemoryUsage 6.39 MB +0% -0% 6.36 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric a38f673 trunk % Change
mediaProcessingJpeg 397.86 ms +0.42% -0.9% 402.06 ms +0.98% -0.72% -1.04%
mediaProcessingAvif 6123.81 ms +0.48% -0.25% 6154.72 ms +0.5% -0.18% -0.5%
mediaProcessingJpegToAvif 4219.73 ms +0.47% -0.24% 4268.22 ms +0.25% -0.23% -1.14%

media-upload

Metric a38f673 trunk % Change
jpegUploadProcessing 1967.26 ms +1.1% -26.33% 1459.07 ms +0.7% -0.24% 34.83%
pngUploadProcessing 203.44 ms +28.08% -17.49% 189 ms +31.78% -8.97% 7.64%
largeJpegUploadProcessing 1486.06 ms +31.09% -2.21% 1469.38 ms +31.19% -0.77% 1.14%
multipleImageUploadProcessing 2013.42 ms +0.5% -0.5% 2023.2 ms +1.07% -0.43% -0.48%

post-editor

Metric a38f673 trunk % Change
serverResponse 334.76 ms +9.82% -6.17% 333.72 ms +5.38% -6.49% 0.31%
firstPaint 381.5 ms +6.8% -35.93% 274.52 ms +44.61% -36.27% 38.97%
domContentLoaded 686.63 ms +1.42% -0.34% 677.83 ms +1.01% -1.39% 1.3%
loaded 687.67 ms +1.43% -0.37% 678.71 ms +1.04% -1.41% 1.32%
firstContentfulPaint 407.34 ms +1.24% -3.66% 401.45 ms +1.86% -3.84% 1.47%
firstBlock 2162.08 ms +0.74% -2.26% 2076.98 ms +0.68% -0.4% 4.1%
type 16.21 ms +2.47% -10.61% 15.97 ms +4.88% -12.84% 1.5%
typeWithoutInspector 15.55 ms +7.85% -8.94% 14.47 ms +3.94% -1.31% 7.46%
typeWithTopToolbar 20.5 ms +5.02% -7.07% 18.47 ms +7.9% -2.11% 10.99%
typeContainer 6.82 ms +5.87% -3.81% 6.49 ms +6.32% -4.78% 5.08%
focus 91.59 ms +12.76% -5.8% 95.11 ms +2.67% -6.1% -3.7%
firstFocus 219.13 ms +0% -0% 201.11 ms +0% -0% 8.96%
selectAll 310.21 ms +3.98% -0.59% 320.35 ms +2.27% -2.09% -3.17%
undo 24.97 ms +3.16% -3.48% 25.9 ms +5.95% -6.29% -3.59%
listViewOpen 64.36 ms +0.87% -13.07% 57.75 ms +11.39% -2.1% 11.45%
inserterOpen 31.79 ms +15.7% -4.28% 32.8 ms +11.59% -9.24% -3.08%
inserterHover 9.45 ms +10.37% -10.9% 9.6 ms +4.48% -8.33% -1.56%
inserterSearch 6.94 ms +2.74% -4.76% 7.34 ms +4.63% -9.95% -5.45%
loadPatterns 495.45 ms +7.35% -3.03% 508.59 ms +5.59% -1.42% -2.58%
wpTotal 325.76 ms +10.06% -6.28% 324.88 ms +5.51% -6.69% 0.27%
wpMemoryUsage 14.73 MB +0% -0% 14.72 MB +0% -0% 0.1%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric a38f673 trunk % Change
serverResponse 534.83 ms +5.08% -3.04% 521.44 ms +6.91% -3.43% 2.57%
firstPaint 340.46 ms +5.05% -19.98% 271.99 ms +13.35% -11.47% 25.17%
domContentLoaded 957.51 ms +0.58% -2.56% 943.11 ms +1.48% -2.22% 1.53%
loaded 958.88 ms +0.56% -2.55% 944.67 ms +1.44% -2.26% 1.5%
firstContentfulPaint 526.28 ms +2.75% -5.26% 513.52 ms +4.13% -2.45% 2.48%
firstBlock 3933.41 ms +1.89% -2.79% 3866.91 ms +1% -2.51% 1.72%
type 21.27 ms +6.96% -1.22% 19.54 ms +8.44% -9.72% 8.85%
navigate 132.17 ms +5.6% -1.68% 117.77 ms +4.39% -1.1% 12.23%
loadPatterns 1193.99 ms +3.28% -6.1% 1197.72 ms +5.58% -6.65% -0.31%
loadPages 1035.54 ms +2.69% -0.77% 1012.81 ms +4.76% -2.69% 2.24%
wpTotal 524.92 ms +5.14% -3.22% 511.21 ms +7% -3.98% 2.68%
wpMemoryUsage 12.77 MB +0% -0% 12.73 MB +0% -0% 0.27%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

53d35e3 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Navigates the list via UP/DOWN arrow keys from action buttons (Site Editor v2) in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' })
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' }) with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' })
    14 × locator resolved to <button type="button" tabindex="-1" class="components-button is-small" id="view-list-0-12-primary-action-view-post">View</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:252:5
Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
a navigation superseded by the traversal discharges to idle in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
SyntaxError: Unexpected token 'o', "not hydrated" is not valid JSON
    at readLog (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:28:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:47:24
    at waitForLogLength (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:46:2)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:693:5
inserts a block should show a blue line indicator in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TimeoutError: locator.boundingBox: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('data-testid=block-list-insertion-point-indicator')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:678:41
should not have a dead zone between blocks (lower) in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeVisible() failed

Locator: locator('role=button[name="Add block"i]')
Expected: visible
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeVisible" locator('role=button[name="Add block"i]') with timeout 5000ms
  - waiting for locator('role=button[name="Add block"i]')

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:981:28
three users concurrently edit a large post with diverse blocks in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.waitFor: Timeout 17500ms exceeded.
Call log:
  - waiting for getByRole('button', { name: /Collaborators list/ }) to be visible

    at map (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:193:7)
    at CollaborationUtils.waitForMutualDiscovery (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:188:10)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:416:28

53d35e3 Run

mirka added 2 commits October 29, 2026 17:30
Tighten the class name format test, test that a token fallback change alone
renames classes, and shorten the changelog entry.
@mirka
mirka requested review from a team and jsnajdr October 29, 2026 09:11
@github-actions github-actions Bot added [Package] Components /packages/components [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Boot /packages/boot [Package] Admin UI /packages/admin-ui [Package] Grid /packages/grid [Package] Widget Dashboard /packages/widget-dashboard labels Oct 29, 2026
@mirka mirka added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Oct 29, 2026
@mirka
mirka marked this pull request as ready for review October 29, 2026 10:08
@mirka
mirka requested a review from retrofox as a code owner October 29, 2026 10:08

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Exploring this locally with an agent to understand defaults and alternative options, I wonder if we need to do all the PostCSS processing in the name generator, or if it's enough to hash from the original raw CSS? In that approach, there's a risk that a change that alters compiled CSS but not the source doesn't change the class name, but I don't know how likely that would be in practice.

@mirka

mirka commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

The raw source would cover most changes, since a .module.scss file is already compiled by Sass when the generator sees it. The problem is the token fallbacks. They come from the installed @wordpress/theme, so two copies built against different theme versions can have the same source but different fallback values. That has happened twice since May (#82505 changed 25 fallback colors, and #82591 reverted them). The extra pass is one PostCSS run per stylesheet, cached per file, so I'd keep it.

@mirka
mirka enabled auto-merge (squash) October 30, 2026 15:07
@mirka
mirka merged commit d473413 into trunk Oct 30, 2026
81 checks passed
@mirka
mirka deleted the fix/wp-build-css-module-class-names-from-css branch October 30, 2026 15:24
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 30, 2026
@github-actions

Copy link
Copy Markdown

There was a conflict while trying to cherry-pick the commit to the wp/7.2 branch. Please resolve the conflict manually and create a PR to the wp/7.2 branch.

PRs to wp/7.2 are similar to PRs to trunk, but you should base your PR on the wp/7.2 branch instead of trunk.

# Checkout the wp/7.2 branch instead of trunk.
git checkout wp/7.2

# Create a new branch for your PR.
git checkout -b my-branch

# Cherry-pick the commit.
git cherry-pick d473413afe2d673444fe60e0f4eb5ac2eb4b35c9

# Check which files have conflicts.
git status

# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue

# Push the branch to the repository
git push origin my-branch

# Create a PR and set the base to the wp/7.2 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

mirka added a commit that referenced this pull request Oct 30, 2026
…'s CSS (#86062)

* wp-build: Derive CSS module class names from each stylesheet's CSS (#85900)

* wp-build: Derive CSS module class names from each stylesheet's CSS

`generateScopedName: '[contenthash]__[local]'` was hashed by `generic-names`
from the file path and local name only, so class names stayed the same across
package versions while the CSS behind them changed. Two bundled copies of a
package then applied their styles to each other's elements.

Hash the relative file path, the CSS of the file that defines each class, and
the local name instead. The CSS comes from `postcss-modules-scope`, which also
covers files reached through `composes`, and is run through the plugins that
precede `postcss-modules` first so that a changed token fallback also renames
the affected classes.

Fixes #85896.

* Add changelog link

* Address review feedback

Tighten the class name format test, test that a token fallback change alone
renames classes, and shorten the changelog entry.

* Add changelog entries to packages that ship CSS modules

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Nikschavan <nikschavan@git.wordpress.org>
(cherry picked from commit d473413)

* Link backport changelog entries to #86062

---------

Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Nikschavan <nikschavan@git.wordpress.org>
@mirka mirka added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Oct 30, 2026
@jsnajdr

jsnajdr commented Nov 2, 2026

Copy link
Copy Markdown
Member

It's unfortunate that we have to compile a .css source twice with the dsTokenFallbacks plugin. Once during the main processing, a second time just for the createScopedNameGenerator hash.

It could be solved by splitting the postcss pipeline into two: one with dsTokenFallbacks, second with the rest. And the second pipeline would have to use a custom FileSystemLoader to load the preprocessed sources. That would ensure that composes syntax:

composes: footer from "../utils/css/overlay-chrome.module.css";

loads the overlay-chrome.module.css file with the fallbacks applied, not the original source.

If we later migrate the postcss pipeline to lightningcss, it could be migrated straightforwardly: LightningCSS has a resolver.read hook that can read file contents from a custom "virtual" source rather than the raw file.

Not sure if this refactoring is worth doing now.

@ciampo

ciampo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

could we leverage the package version instead of the CSS contents?

@mirka mirka added has dev note when dev note is done (for upcoming WordPress release) and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels Nov 5, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…ordPress#85900)

* wp-build: Derive CSS module class names from each stylesheet's CSS

`generateScopedName: '[contenthash]__[local]'` was hashed by `generic-names`
from the file path and local name only, so class names stayed the same across
package versions while the CSS behind them changed. Two bundled copies of a
package then applied their styles to each other's elements.

Hash the relative file path, the CSS of the file that defines each class, and
the local name instead. The CSS comes from `postcss-modules-scope`, which also
covers files reached through `composes`, and is run through the plugins that
precede `postcss-modules` first so that a changed token fallback also renames
the affected classes.

Fixes WordPress#85896.

* Add changelog link

* Address review feedback

Tighten the class name format test, test that a token fallback change alone
renames classes, and shorten the changelog entry.

* Add changelog entries to packages that ship CSS modules

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Nikschavan <nikschavan@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core has dev note when dev note is done (for upcoming WordPress release) [Package] Admin UI /packages/admin-ui [Package] Boot /packages/boot [Package] Components /packages/components [Package] Grid /packages/grid [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Widget Dashboard /packages/widget-dashboard [Package] wp-build /packages/wp-build [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp-build: Bundled copies of a package share CSS module class names across versions

4 participants