fix(vite): keep each environment's outDir mapped to its own css-post plugin - #5330
Merged
Merged
Conversation
✅ Deploy Preview for unocss ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
commit: |
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.
Fixes #5329.
Since #5324,
configResolvedregistersvite:css-post/vite:cssfor every environment'sbuild.outDir. That's correct for a shared config build (builder.sharedConfigBuild: true, the #5323 scenario), where all environments share one resolved config and one set of css plugin instances.But when a framework passes the plugin inline without
sharedConfigBuild(as Astro does), Vite resolves a separate config per environment — each with its ownvite:css-postinstance — and callsconfigResolvedon the same UnoCSS plugin instance once per environment. Each call overwrote every environment's outDir entry, so the last-resolved environment's css-post instance won for all keys. An environment'srenderChunkthen invoked a css-post handler bound to a foreign config whosebuildStartnever ran, crashing withCannot read properties of undefined (reading 'get')incssModulesCache.get(config).get(id)— the Astrooutput: 'server'build failure in #5329.The fix keeps each resolved config's own
build.outDir(androllupOptions.outputdirs) registration authoritative, while environment-derived dirs only fill gaps. Each environment's build now finds the css-post instance from its own config, whose module cache is seeded by that build'sbuildStart. Shared-config builds are unaffected: there is a single resolved config, so all dirs still map to its instance and the #5323 fixture still passes.Added a fixture (
test/fixtures/vite-environments-isolated) that mirrors the Astro setup — inline plugin, per-environment configs, client built first — which reproduces the exactCannot read properties of undefined (reading 'get')crash before the fix. Also verified the original Astro repro from #5329 (output: 'server'+@astrojs/node+ prerendered page) builds successfully with this patch and matches 66.10.0 behaviour.PR created with the help of an agent.