mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Fix asset propagation regression in 3.5 (#9069)
This commit is contained in:
parent
44bfc9bbba
commit
50164f5e37
7 changed files with 51 additions and 10 deletions
5
.changeset/quick-parrots-judge.md
Normal file
5
.changeset/quick-parrots-judge.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"astro": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix a regression introduced in 3.5.0 related to content collection styles
|
|
@ -169,7 +169,7 @@ export function astroConfigBuildPlugin(
|
||||||
const pageData = getPageDataByViteID(internals, pageViteID);
|
const pageData = getPageDataByViteID(internals, pageViteID);
|
||||||
if (!pageData) continue;
|
if (!pageData) continue;
|
||||||
|
|
||||||
const _entryCss = internals.propagatedStylesMap?.get(id);
|
const _entryCss = pageData.propagatedStyles?.get(id);
|
||||||
const _entryScripts = pageData.propagatedScripts?.get(id);
|
const _entryScripts = pageData.propagatedScripts?.get(id);
|
||||||
if (_entryCss) {
|
if (_entryCss) {
|
||||||
for (const value of _entryCss) {
|
for (const value of _entryCss) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ export function astroContentVirtualModPlugin({
|
||||||
hydratedComponents: [],
|
hydratedComponents: [],
|
||||||
clientOnlyComponents: [],
|
clientOnlyComponents: [],
|
||||||
scripts: [],
|
scripts: [],
|
||||||
containsHead: true,
|
containsHead: false,
|
||||||
propagation: 'in-tree',
|
propagation: 'in-tree',
|
||||||
pageOptions: {},
|
pageOptions: {},
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,6 +59,8 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
|
||||||
const pagesToCss: Record<string, Record<string, { order: number; depth: number }>> = {};
|
const pagesToCss: Record<string, Record<string, { order: number; depth: number }>> = {};
|
||||||
const pagesToPropagatedCss: Record<string, Record<string, Set<string>>> = {};
|
const pagesToPropagatedCss: Record<string, Record<string, Set<string>>> = {};
|
||||||
|
|
||||||
|
const isContentCollectionCache = options.buildOptions.settings.config.output === 'static' && options.buildOptions.settings.config.experimental.contentCollectionCache;
|
||||||
|
|
||||||
const cssBuildPlugin: VitePlugin = {
|
const cssBuildPlugin: VitePlugin = {
|
||||||
name: 'astro:rollup-plugin-build-css',
|
name: 'astro:rollup-plugin-build-css',
|
||||||
|
|
||||||
|
@ -93,10 +95,7 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
|
||||||
// so they can be injected where needed
|
// so they can be injected where needed
|
||||||
const chunkId = assetName.createNameHash(id, [id]);
|
const chunkId = assetName.createNameHash(id, [id]);
|
||||||
internals.cssModuleToChunkIdMap.set(id, chunkId);
|
internals.cssModuleToChunkIdMap.set(id, chunkId);
|
||||||
if (
|
if (isContentCollectionCache) {
|
||||||
options.buildOptions.settings.config.output === 'static' &&
|
|
||||||
options.buildOptions.settings.config.experimental.contentCollectionCache
|
|
||||||
) {
|
|
||||||
// TODO: Handle inlining?
|
// TODO: Handle inlining?
|
||||||
const propagatedStyles =
|
const propagatedStyles =
|
||||||
internals.propagatedStylesMap.get(pageInfo.id) ?? new Set();
|
internals.propagatedStylesMap.get(pageInfo.id) ?? new Set();
|
||||||
|
@ -251,9 +250,16 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
|
||||||
// return early if the stylesheet needing propagation has already been included
|
// return early if the stylesheet needing propagation has already been included
|
||||||
if (pageData.styles.some((s) => s.sheet === sheet)) return;
|
if (pageData.styles.some((s) => s.sheet === sheet)) return;
|
||||||
|
|
||||||
const propagatedStyles =
|
let propagatedStyles: Set<StylesheetAsset>;
|
||||||
internals.propagatedStylesMap.get(pageInfoId) ??
|
if (isContentCollectionCache) {
|
||||||
internals.propagatedStylesMap.set(pageInfoId, new Set()).get(pageInfoId)!;
|
propagatedStyles =
|
||||||
|
internals.propagatedStylesMap.get(pageInfoId) ??
|
||||||
|
internals.propagatedStylesMap.set(pageInfoId, new Set()).get(pageInfoId)!;
|
||||||
|
} else {
|
||||||
|
propagatedStyles =
|
||||||
|
pageData.propagatedStyles.get(pageInfoId) ??
|
||||||
|
pageData.propagatedStyles.set(pageInfoId, new Set()).get(pageInfoId)!;
|
||||||
|
}
|
||||||
|
|
||||||
propagatedStyles.add(sheet);
|
propagatedStyles.add(sheet);
|
||||||
sheetAddedToPage = true;
|
sheetAddedToPage = true;
|
||||||
|
|
|
@ -95,6 +95,14 @@ describe('Content Collections', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Propagation', () => {
|
||||||
|
it('Applies styles', async () => {
|
||||||
|
const html = await fixture.readFile('/propagation/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('style').text()).to.include('content:"works!"');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
describe('Entry', () => {
|
describe('Entry', () => {
|
||||||
let json;
|
let json;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ describe('astro:image', () => {
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dynamic route images are built at response time sss', async () => {
|
it('dynamic route images are built at response time', async () => {
|
||||||
const app = await fixture.loadTestAdapterApp();
|
const app = await fixture.loadTestAdapterApp();
|
||||||
let request = new Request('http://example.com/');
|
let request = new Request('http://example.com/');
|
||||||
let response = await app.render(request);
|
let response = await app.render(request);
|
||||||
|
|
22
packages/astro/test/fixtures/content-collections/src/pages/propagation.astro
vendored
Normal file
22
packages/astro/test/fixtures/content-collections/src/pages/propagation.astro
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
import { getCollection } from "astro:content";
|
||||||
|
const posts = await getCollection("with-schema-config");
|
||||||
|
---
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div class="foo">
|
||||||
|
<div>Hello World</div>
|
||||||
|
<span>Styles?</span>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.foo {
|
||||||
|
background-color: blue;
|
||||||
|
}
|
||||||
|
span::after {
|
||||||
|
content: "works!";
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Add table
Reference in a new issue