diff --git a/.changeset/seven-zoos-lie.md b/.changeset/seven-zoos-lie.md new file mode 100644 index 0000000000..b19de1b05d --- /dev/null +++ b/.changeset/seven-zoos-lie.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Remove regression when there is duplicate client/server CSS diff --git a/packages/astro/src/core/build/vite-plugin-css.ts b/packages/astro/src/core/build/vite-plugin-css.ts index 76f19c8f35..28e88cf65d 100644 --- a/packages/astro/src/core/build/vite-plugin-css.ts +++ b/packages/astro/src/core/build/vite-plugin-css.ts @@ -148,6 +148,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] if (Object.keys(c.modules).every((id) => internals.cssChunkModuleIds.has(id))) { for (const importedCssImport of meta.importedCss) { delete bundle[importedCssImport]; + meta.importedCss.delete(importedCssImport); } return; } diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index 5a32b3ad6f..1b1391f97d 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -8,6 +8,7 @@ import { expect } from 'chai'; import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; +/** @type {import('./test-utils').Fixture} */ let fixture; describe('CSS', function () { @@ -360,6 +361,16 @@ describe('CSS', function () { // SvelteDynamic styles is already included in the main page css asset const unusedCssAsset = bundledAssets.find((asset) => /SvelteDynamic\..*\.css/.test(asset)); expect(unusedCssAsset, 'Found unused style ' + unusedCssAsset).to.be.undefined; + + let foundVitePreloadCSS = false; + const bundledJS = await fixture.glob('**/*.?(m)js'); + for(const filename of bundledJS) { + const content = await fixture.readFile(filename); + if(content.match(/ReactDynamic\..*\.css/)) { + foundVitePreloadCSS = filename; + } + } + expect(foundVitePreloadCSS).to.equal(false, 'Should not have found a preload for the dynamic CSS'); }); }); }); diff --git a/packages/astro/test/fixtures/0-css/src/components/ReactDynamic.jsx b/packages/astro/test/fixtures/0-css/src/components/ReactDynamic.jsx index 14527edb41..bdc7177ec2 100644 --- a/packages/astro/test/fixtures/0-css/src/components/ReactDynamic.jsx +++ b/packages/astro/test/fixtures/0-css/src/components/ReactDynamic.jsx @@ -1,5 +1,13 @@ import React from 'react'; +const ReactLazy = React.lazy(() => import('./ReactLazy')); + export default function() { - return
; -} \ No newline at end of file + return ( +