Skip to content

fix(vite): keep each environment's outDir mapped to its own css-post plugin - #5330

Merged
antfu merged 1 commit into
unocss:mainfrom
antfubot:fix/vite-env-css-post-per-config
Sep 11, 2026
Merged

antfu merged 1 commit into
unocss:mainfrom
antfubot:fix/vite-env-css-post-per-config

Conversation

@antfubot

Copy link
Copy Markdown
Contributor

Fixes #5329.

Since #5324, configResolved registers vite:css-post/vite:css for every environment's build.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 own vite:css-post instance — and calls configResolved on 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's renderChunk then invoked a css-post handler bound to a foreign config whose buildStart never ran, crashing with Cannot read properties of undefined (reading 'get') in cssModulesCache.get(config).get(id) — the Astro output: 'server' build failure in #5329.

The fix keeps each resolved config's own build.outDir (and rollupOptions.output dirs) 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's buildStart. 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 exact Cannot 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.

@antfubot
antfubot requested review from antfu and zyyv as code owners September 11, 2026 00:58
@netlify

netlify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 412505d
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/6aa3524d15573f0008d658b4
😎 Deploy Preview https://deploy-preview-5330--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 412505d

@antfu
antfu merged commit 6e5c97b into unocss:main Sep 11, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Astro output: 'server' builds crash since 66.10.1: cssModulesCache.get(config) is undefined for the prerender environment

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo