fix(css): keep deprecated name/originalFileName in synthetic assetFileNames call#22439
Merged
sapphi-red merged 2 commits intoMay 14, 2026
Merged
Conversation
…`assetFileNames` call `getCssAssetDirname` invokes the user's `assetFileNames` callback to figure out which directory the CSS file ends up in, so url() rewrites can compute a correct relative path. The rolldown migration dropped `name` and `originalFileName` (singular) from that synthetic call. Both fields are marked deprecated in rolldown's `PreRenderedAsset` type but are still populated for the real asset emit. User callbacks commonly branch on `chunkInfo.name` (the karlvr/vite-relative-base-bug repro does), so the synthetic call now misses the css branch and falls through to the default pattern. The dirname then comes out as `.` instead of e.g. `css`, and `url(../img/foo.png)` regresses to `url(./img/foo.png)`. Restore the two deprecated fields in the synthetic call so it matches what user code sees during the real emit. fix vitejs#22434 Signed-off-by: ChrisJr404 <chris@hacknow.com>
sapphi-red
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
getCssAssetDirnamecalls the user'sassetFileNamesonce with a fakePreRenderedAssetto find out which directory the emitted CSS will land in. The rolldown migration in 47a4d50 dropped the deprecatednameandoriginalFileName(singular) fields from that synthetic call.Both fields are flagged
@deprecatedon rolldown'sPreRenderedAssettype, but rolldown still populates them when it really emits the asset. User-providedassetFileNamescallbacks routinely branch onchunkInfo.name, including the one in the reproduction for #22434:During the real emit
chunkInfo.nameismain.cssand the CSS lands incss/. During the synthetic call fromgetCssAssetDirnamenameisundefined, the css branch is skipped, the fallback[name]-[hash].[ext]is returned,path.dirnameof that is., and sourl()rewriting computes paths relative to the build root rather than relative tocss/. The CSS ends up containingurl(./img/foo-*.png)when it should beurl(../img/foo-*.png).This restores
nameandoriginalFileNameon the synthetic call so it matches what user code sees during the real emit. The string andundefined(no callback) branches were already correct since they derive the dirname from the pattern itself.Verification
Reproduced against
https://github.com/karlvr/vite-relative-base-bugwith vite 8.0.12: emitsurl(./img/foo-*.png). With this patch the same build emitsurl(../img/foo-*.png), matching vite 7.Added a regression test in
build.spec.tsthat runs abuild()programmatically withbase: './'and a functionassetFileNamesthat splits CSS intocss/and images intoimg/. The test asserts the emitted CSS containsurl(../img/foo-*.png).pnpm test-unitinpackages/vite(747 passed, 4 skipped).VITE_TEST_BUILD=1 pnpm exec vitest run playground/assets/__tests__/relative-base/(34 passed).VITE_TEST_BUILD=1 pnpm exec vitest run playground/css/__tests__/(107 passed, 3 skipped).What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).Closes #22434