Skip to content

Commit

Permalink
Remove old CSS deduping strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed May 26, 2023
1 parent f8b4abe commit 93a9e7a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 27 deletions.
6 changes: 0 additions & 6 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { ASTRO_PAGE_EXTENSION_POST_PATTERN, ASTRO_PAGE_MODULE_ID } from './plugi
import type { PageBuildData, StylesheetAsset, ViteID } from './types';

export interface BuildInternals {
/**
* The module ids of all CSS chunks, used to deduplicate CSS assets between
* SSR build and client build in vite-plugin-css.
*/
cssChunkModuleIds: Set<string>;
/**
* Each CSS module is named with a chunk id derived from the Astro pages they
* are used in by default. It's easy to crawl this relation in the SSR build as
Expand Down Expand Up @@ -100,7 +95,6 @@ export function createBuildInternals(): BuildInternals {
const hoistedScriptIdToPagesMap = new Map<string, Set<string>>();

return {
cssChunkModuleIds: new Set(),
cssModuleToChunkId: new Map(),
hoistedScriptIdToHoistedMap,
hoistedScriptIdToPagesMap,
Expand Down
21 changes: 0 additions & 21 deletions packages/astro/src/core/build/plugins/plugin-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,6 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
// Skip if the chunk has no CSS, we want to handle CSS chunks only
if (meta.importedCss.size < 1) continue;

// In the SSR build, keep track of all CSS chunks' modules as the client build may
// duplicate them, e.g. for `client:load` components that render in SSR and client
// for hydation.
if (options.target === 'server') {
for (const id of Object.keys(chunk.modules)) {
internals.cssChunkModuleIds.add(id);
}
}

// In the client build, we bail if the chunk is a duplicated CSS chunk tracked from
// above. We remove all the importedCss to prevent emitting the CSS asset.
if (options.target === 'client') {
if (Object.keys(chunk.modules).every((id) => internals.cssChunkModuleIds.has(id))) {
for (const importedCssImport of meta.importedCss) {
delete bundle[importedCssImport];
meta.importedCss.delete(importedCssImport);
}
return;
}
}

// For the client build, client:only styles need to be mapped
// over to their page. For this chunk, determine if it's a child of a
// client:only component and if so, add its CSS to the page it belongs to.
Expand Down

0 comments on commit 93a9e7a

Please sign in to comment.