Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,16 @@ async function buildEnvironments(opts: StaticBuildOptions, internals: BuildInter
}
return [prefix, cleanChunkName(name), suffix].join('');
},
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
assetFileNames(assetInfo) {
// Strip the @_@ extension-masking pattern from asset names, just like chunkFileNames above.
// The @_@ pattern is an internal mechanism for virtual module IDs and should not leak into output filenames.
const name = assetInfo.names?.[0] ?? '';
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
return `${settings.config.build.assets}/${sanitizedName}.[hash][extname]`;
}
return `${settings.config.build.assets}/[name].[hash][extname]`;
},
...viteConfig.build?.rollupOptions?.output,
entryFileNames(chunkInfo) {
if (chunkInfo.facadeModuleId?.startsWith(VIRTUAL_PAGE_RESOLVED_MODULE_ID)) {
Expand Down Expand Up @@ -424,7 +433,16 @@ async function buildEnvironments(opts: StaticBuildOptions, internals: BuildInter
chunkFileNames(chunkInfo) {
return `${settings.config.build.assets}/${cleanChunkName(chunkInfo.name)}.[hash].js`;
},
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
assetFileNames(assetInfo) {
// Strip the @_@ extension-masking pattern from asset names.
// The @_@ pattern is an internal mechanism for virtual module IDs and should not leak into output filenames.
const name = assetInfo.names?.[0] ?? '';
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
return `${settings.config.build.assets}/${sanitizedName}.[hash][extname]`;
}
return `${settings.config.build.assets}/[name].[hash][extname]`;
},
...viteConfig.environments?.client?.build?.rollupOptions?.output,
},
},
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/test/css-deduplication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ describe('CSS deduplication for hydrated components', () => {
it('should not duplicate CSS for hydrated components', async () => {
const assets = await fixture.readdir('/_astro');

// Generated file for Counter.css (filename format changed in main-next)
const COUNTER_CSS_PATH = '/_astro/index@_@astro.DbgLc3FE.css';
// Generated file for Counter.css — find it dynamically since the hash may change
const counterCssFile = assets.find((f) => f.startsWith('index.') && f.endsWith('.css'));
assert.ok(counterCssFile, 'Expected a CSS file starting with "index."');
const COUNTER_CSS_PATH = `/_astro/${counterCssFile}`;
let file = await fixture.readFile(COUNTER_CSS_PATH);
file = file.replace(/\s+/g, '');

Expand Down
Loading