Skip to content

Commit 18552c7

Browse files
ematipicodelucissarah11918
authored
Revert "fix(build): Prevent duplicate CSS for hydrated client components" (#14612)
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: delucis <357379+delucis@users.noreply.github.com> Co-authored-by: sarah11918 <5098874+sarah11918@users.noreply.github.com>
1 parent 54803d7 commit 18552c7

File tree

10 files changed

+8
-218
lines changed

10 files changed

+8
-218
lines changed

.changeset/puny-yaks-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a regression introduced in Astro v5.14.7 that caused `?url` imports to not work correctly. This release reverts [#14142](https://github.com/withastro/astro/pull/14142).

packages/astro/src/core/build/plugins/plugin-css.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
8080
// and that's okay. We can use Rollup's default chunk strategy instead as these CSS
8181
// are outside of the SSR build scope, which no dedupe is needed.
8282
if (options.target === 'client') {
83-
// Find the chunkId for this CSS module in the server build.
84-
// If it exists, we can use it to ensure the client build matches the server
85-
// build and doesn't create a duplicate chunk.
86-
return internals.cssModuleToChunkIdMap.get(id);
83+
return internals.cssModuleToChunkIdMap.get(id)!;
8784
}
8885

8986
const ctx = { getModuleInfo: meta.getModuleInfo };
@@ -96,7 +93,6 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
9693
return chunkId;
9794
}
9895
}
99-
10096
const chunkId = createNameForParentPages(id, meta);
10197
internals.cssModuleToChunkIdMap.set(id, chunkId);
10298
return chunkId;
@@ -234,12 +230,8 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
234230
sheetAddedToPage = true;
235231
}
236232

237-
const wasInlined = toBeInlined && sheetAddedToPage;
238-
const isOrphaned = !sheetAddedToPage;
239-
if (wasInlined || isOrphaned) {
240-
// wasInlined : CSS is already added to all used pages
241-
// isOrphaned : CSS is already used in a merged chunk
242-
// we can delete it from the bundle
233+
if (toBeInlined && sheetAddedToPage) {
234+
// CSS is already added to all used pages, we can delete it from the bundle
243235
// and make sure no chunks reference it via `importedCss` (for Vite preloading)
244236
// to avoid duplicate CSS.
245237
delete bundle[id];

packages/astro/test/css-deduplication.test.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/astro.config.mjs

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/package.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/src/components/Counter.css

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/src/components/Counter.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/src/pages/index.astro

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/astro/test/fixtures/css-deduplication/tsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)