summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-09-06 15:03:02 -0400
committerGravatar GitHub <noreply@github.com> 2022-09-06 15:03:02 -0400
commit307b7b97ce79d076ceb4fdc25fd28a27077deb34 (patch)
tree23596251db90cdaf78fd57cf7839b2aff37f3c90
parenteb1862b4e68b399eecc7267ea9e0bee36983b0cb (diff)
downloadastro-307b7b97ce79d076ceb4fdc25fd28a27077deb34.tar.gz
astro-307b7b97ce79d076ceb4fdc25fd28a27077deb34.tar.zst
astro-307b7b97ce79d076ceb4fdc25fd28a27077deb34.zip
When removing duplicate CSS, also remove from metadata (#4643)
* When removing duplicate CSS, also remove from metadata * Adding a changeset
-rw-r--r--.changeset/seven-zoos-lie.md5
-rw-r--r--packages/astro/src/core/build/vite-plugin-css.ts1
-rw-r--r--packages/astro/test/0-css.test.js11
-rw-r--r--packages/astro/test/fixtures/0-css/src/components/ReactDynamic.jsx12
-rw-r--r--packages/astro/test/fixtures/0-css/src/components/ReactLazy.jsx6
-rw-r--r--packages/astro/test/fixtures/0-css/src/components/ReactLazy.module.css3
-rw-r--r--packages/astro/test/test-utils.js5
7 files changed, 41 insertions, 2 deletions
diff --git a/.changeset/seven-zoos-lie.md b/.changeset/seven-zoos-lie.md
new file mode 100644
index 000000000..b19de1b05
--- /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 76f19c8f3..28e88cf65 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 5a32b3ad6..1b1391f97 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 14527edb4..bdc7177ec 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 <div></div>;
-} \ No newline at end of file
+ return (
+ <div>
+ <React.Suspense>
+ <ReactLazy />
+ </React.Suspense>
+ </div>
+ );
+}
diff --git a/packages/astro/test/fixtures/0-css/src/components/ReactLazy.jsx b/packages/astro/test/fixtures/0-css/src/components/ReactLazy.jsx
new file mode 100644
index 000000000..9c731ed68
--- /dev/null
+++ b/packages/astro/test/fixtures/0-css/src/components/ReactLazy.jsx
@@ -0,0 +1,6 @@
+import React from 'react';
+import mod from './ReactLazy.module.css';
+
+export default function() {
+ return <div className={mod.lazy}></div>;
+}
diff --git a/packages/astro/test/fixtures/0-css/src/components/ReactLazy.module.css b/packages/astro/test/fixtures/0-css/src/components/ReactLazy.module.css
new file mode 100644
index 000000000..1f188e31d
--- /dev/null
+++ b/packages/astro/test/fixtures/0-css/src/components/ReactLazy.module.css
@@ -0,0 +1,3 @@
+.lazy {
+ background: yellow;
+}
diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js
index ded7e7745..72945d8a3 100644
--- a/packages/astro/test/test-utils.js
+++ b/packages/astro/test/test-utils.js
@@ -9,6 +9,7 @@ import preview from '../dist/core/preview/index.js';
import { nodeLogDestination } from '../dist/core/logger/node.js';
import os from 'os';
import stripAnsi from 'strip-ansi';
+import fastGlob from 'fast-glob';
// polyfill WebAPIs to globalThis for Node v12, Node v14, and Node v16
polyfill(globalThis, {
@@ -30,6 +31,7 @@ polyfill(globalThis, {
* @property {(path: string) => Promise<string>} readFile
* @property {(path: string, updater: (content: string) => string) => Promise<void>} writeFile
* @property {(path: string) => Promise<string[]>} readdir
+ * @property {(pattern: string) => Promise<string[]>} glob
* @property {() => Promise<DevServer>} startDevServer
* @property {() => Promise<PreviewServer>} preview
* @property {() => Promise<void>} clean
@@ -147,6 +149,9 @@ export async function loadFixture(inlineConfig) {
readFile: (filePath) =>
fs.promises.readFile(new URL(filePath.replace(/^\//, ''), config.outDir), 'utf8'),
readdir: (fp) => fs.promises.readdir(new URL(fp.replace(/^\//, ''), config.outDir)),
+ glob: (p) => fastGlob(p, {
+ cwd: fileURLToPath(config.outDir)
+ }),
clean: async () => {
await fs.promises.rm(config.outDir, { maxRetries: 10, recursive: true, force: true });
},