fix: Allow new Vite v8 outputOptions callback shape#604
Open
raybrownco wants to merge 1 commit intoElMassimo:mainfrom
Open
fix: Allow new Vite v8 outputOptions callback shape#604raybrownco wants to merge 1 commit intoElMassimo:mainfrom
outputOptions callback shape#604raybrownco wants to merge 1 commit intoElMassimo:mainfrom
Conversation
Vite v8 (which uses Rolldown) changed the object shape passed to the `assetFileNames` callback. In Vite v7 (which uses Rollup), the callback received a `PreRenderedAsset` object with a singular `name: string | undefined` field. In Vite v8, Vite's internal `vite:css-post` plugin calls the same `assetFileNames` function with a plural `names: string[]` field instead. This matches the Rolldown `PreRenderedAsset` interface. See: https://github.com/rolldown/rolldown/blob/a71934bf/packages/rolldown/src/options/output-options.ts#L66-L77
Contributor
Author
|
@ElMassimo Ready for your review: this PR fixes a bug that we ran into when attempting to upgrade Vite from v7 to v8 in one of our Rails projects. Thanks in advance for your consideration! Let me know if you object to any of these changes - I'm more than happy to accept feedback. |
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 📖
Fix a build issue related to Vite 8's handling of the
assetFileNamescallback, which is manually typed in theoutputFileName()function.Background 📜
Vite v8 (which uses Rolldown) changed the object shape passed to the
assetFileNamescallback.In Vite v7 (which uses Rollup), the callback received a
PreRenderedAssetobject with a singularname: string | undefinedfield.In Vite v8, Vite's internal
vite:css-postplugin calls the sameassetFileNamesfunction with a pluralnames: string[]field instead. This matches the RolldownPreRenderedAssetinterface. See: https://github.com/rolldown/rolldown/blob/a71934bf/packages/rolldown/src/options/output-options.ts#L66-L77The Fix 🔨
First, we define a
PreRenderedAssetinterface that handles both shapes:Then, determine which value to use within the
outputFileName()function:Screenshots 📷
A Rails project with
vite_rails(3.0.19) andvite_ruby(3.9.2) began to fail after updatingvitefrom 7.3.2 to 8.0.10: