Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#1918·stylex

[unplugin] CSS-only change renames the CSS asset but not the chunk that references it

Author: bjcggCreated Sep 29, 2026Updated Sep 29, 2026

Describe the issue

With @stylexjs/[email protected] and Vite 8.3.1, a change that reaches only the StyleX CSS renames the CSS asset but not the JS chunk that contains the CSS file name.

The Vite hook appends the StyleX rules in generateBundle. replaceCssAssetWithHashedCopy emits a new CSS asset with a new hash, and replaceBundleReferences rewrites the old CSS file name inside every chunk. At that point Rolldown has already hashed the chunks, so the rewritten chunk keeps its old file name with new bytes.

A defineVars value change shows it clearly, because the compiled JS does not contain the value. The CSS file name changes. The entry chunk keeps its name, and its bytes change because it now contains the new CSS file name.

This matters when hashed assets are served as immutable, which is the usual setup. A browser or CDN that cached the old index-<hash>.js keeps using it, and that file points to a CSS file that the new deploy no longer has.

This is different from #1889. There the CSS file name did not change. Here the CSS name changes, but the chunk that refers to it does not.

Expected behavior

When the final CSS content changes, every chunk whose code contains the CSS file name also gets a new file name. The same input gives the same file names.

Steps to reproduce

macOS 27.2 (arm64), Node.js 22.22.3, Bun 1.4.2, Vite 8.3.1, @stylexjs/stylex and @stylexjs/unplugin 0.19.1.

  1. Create the files in the test case below.
  2. Run bun install and bunx vite build.
  3. Change #ff0000 to #00ff00 in src/tokens.stylex.js.
  4. Run bunx vite build again and compare dist/assets.

Result:

Build CSS Entry Entry MD5
1 app-zr-JsEwU.css index-Bd-fHSM-.js 4f8ec0f7e9d1832e954a85a880cbbf09
2 app-CYVd4w3L.css index-Bd-fHSM-.js 4302217fe03a62b205e687c3ea0d8ce2

The entry keeps its name, but its content changed: build 2 contains app-CYVd4w3L.css.

Test case

package.json

json
{
  "name": "stylex-hash-repro",
  "private": true,
  "type": "module",
  "dependencies": { "@stylexjs/stylex": "0.19.1" },
  "devDependencies": { "@stylexjs/unplugin": "0.19.1", "vite": "8.3.1" }
}

vite.config.js

javascript
import stylex from "@stylexjs/unplugin";
import { defineConfig } from "vite";

export default defineConfig({ plugins: [stylex.vite()] });

index.html

xml
<!doctype html>
<html><head><meta charset="utf-8" /></head><body><script type="module" src="/src/main.js"></script></body></html>

src/app.css

css
body { margin: 0; }

src/tokens.stylex.js

javascript
import * as stylex from "@stylexjs/stylex";

export const tokens = stylex.defineVars({ accent: "#ff0000" });

src/main.js

javascript
import * as stylex from "@stylexjs/stylex";
import cssUrl from "./app.css?url";
import { tokens } from "./tokens.stylex.js";

const styles = stylex.create({ root: { color: tokens.accent } });

const link = document.createElement("link");
link.rel = "stylesheet";
link.href = cssUrl;
document.head.append(link);
document.body.className = stylex.props(styles.root).className ?? "";

The ?url import is how TanStack Start and other SSR frameworks link a global stylesheet from JS.

Additional comments

Our workaround is a small Vite plugin placed before stylex.vite(). It records the source of each module that imports @stylexjs/stylex in transform. In augmentChunkHash, it returns a SHA-256 digest of those sources for each chunk that contains the app.css?url module. After this change, the same test renames the CSS, the entry and the SSR chunk that holds the CSS URL.

A fix inside the plugin could use augmentChunkHash with a digest of the collected rules. All modules are transformed by then, so collectCss() has the final rule set. It would return that digest for chunks that import the target CSS asset.

Source: facebook/stylex

View original on GitHubView discussion on GitHub