Skip to content

[unplugin] Rehash the Vite stylesheet when cssCodeSplit is false - #1905

Open
kwy404 wants to merge 1 commit into
facebook:mainfrom
kwy404:fix-vite-css-hash-single-stylesheet
Open

kwy404 wants to merge 1 commit into
facebook:mainfrom
kwy404:fix-vite-css-hash-single-stylesheet

Conversation

@kwy404

@kwy404 kwy404 commented Sep 24, 2026

Copy link
Copy Markdown

What changed / motivation ?

With build.cssCodeSplit: false, Vite emits the single stylesheet in its own generateBundle hook. Because the StyleX plugin is enforce: 'pre', its generateBundle ran first, found no CSS asset, and the rules were appended later in writeBundle, so the content hash in the filename stayed the same after a StyleX-only edit. This runs generateBundle with order: 'post' so the stylesheet is already in the bundle and goes through the existing replaceCssAssetWithHashedCopy path.

Linked PR/Issues

Fixes #1889

Additional Context

Added a test that checks the hook order, and updated the two existing tests to call generateBundle.handler. The unplugin Jest suite passes, and eslint and prettier are clean on the changed files.

I also checked a local Vite 7 build with cssCodeSplit: false that changes paddingTop: 16 to 32. Before, both builds emitted style-TZrNw7dA.css. After, they emit style-Brnp5ict.css and style-XC-JYDyN.css, and index.html points to the new file. With cssCodeSplit: true the output still changes its name as before.

Pre-flight checklist

With `build.cssCodeSplit: false`, Vite emits the single stylesheet in its
own generateBundle hook. The StyleX hook ran first because the plugin is
`enforce: 'pre'`, found no CSS asset, and fell back to appending the rules
in writeBundle, so the content hash in the filename never changed.

Run generateBundle with `order: 'post'` so the stylesheet already exists
and goes through the existing rehash path.

Fixes facebook#1889
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026
@vercel

vercel Bot commented Sep 24, 2026

Copy link
Copy Markdown

@kwy404 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite CSS filename does not change after a StyleX-only edit with cssCodeSplit: false

1 participant