summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/quick-parrots-judge.md5
-rw-r--r--packages/astro/src/content/vite-plugin-content-assets.ts2
-rw-r--r--packages/astro/src/content/vite-plugin-content-virtual-mod.ts2
-rw-r--r--packages/astro/src/core/build/plugins/plugin-css.ts20
-rw-r--r--packages/astro/test/content-collections.test.js8
-rw-r--r--packages/astro/test/core-image.test.js2
-rw-r--r--packages/astro/test/fixtures/content-collections/src/pages/propagation.astro22
7 files changed, 51 insertions, 10 deletions
diff --git a/.changeset/quick-parrots-judge.md b/.changeset/quick-parrots-judge.md
new file mode 100644
index 000000000..44675ce81
--- /dev/null
+++ b/.changeset/quick-parrots-judge.md
@@ -0,0 +1,5 @@
+---
+"astro": patch
+---
+
+Fix a regression introduced in 3.5.0 related to content collection styles
diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts
index d1f2ca4ce..5b79d5653 100644
--- a/packages/astro/src/content/vite-plugin-content-assets.ts
+++ b/packages/astro/src/content/vite-plugin-content-assets.ts
@@ -169,7 +169,7 @@ export function astroConfigBuildPlugin(
const pageData = getPageDataByViteID(internals, pageViteID);
if (!pageData) continue;
- const _entryCss = internals.propagatedStylesMap?.get(id);
+ const _entryCss = pageData.propagatedStyles?.get(id);
const _entryScripts = pageData.propagatedScripts?.get(id);
if (_entryCss) {
for (const value of _entryCss) {
diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
index 941359c97..92d47003e 100644
--- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
+++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts
@@ -76,7 +76,7 @@ export function astroContentVirtualModPlugin({
hydratedComponents: [],
clientOnlyComponents: [],
scripts: [],
- containsHead: true,
+ containsHead: false,
propagation: 'in-tree',
pageOptions: {},
},
diff --git a/packages/astro/src/core/build/plugins/plugin-css.ts b/packages/astro/src/core/build/plugins/plugin-css.ts
index 1073ed056..59a5aa3c6 100644
--- a/packages/astro/src/core/build/plugins/plugin-css.ts
+++ b/packages/astro/src/core/build/plugins/plugin-css.ts
@@ -59,6 +59,8 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
const pagesToCss: Record<string, Record<string, { order: number; depth: number }>> = {};
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 = {
name: 'astro:rollup-plugin-build-css',
@@ -93,10 +95,7 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
// so they can be injected where needed
const chunkId = assetName.createNameHash(id, [id]);
internals.cssModuleToChunkIdMap.set(id, chunkId);
- if (
- options.buildOptions.settings.config.output === 'static' &&
- options.buildOptions.settings.config.experimental.contentCollectionCache
- ) {
+ if (isContentCollectionCache) {
// TODO: Handle inlining?
const propagatedStyles =
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
if (pageData.styles.some((s) => s.sheet === sheet)) return;
- const propagatedStyles =
- internals.propagatedStylesMap.get(pageInfoId) ??
- internals.propagatedStylesMap.set(pageInfoId, new Set()).get(pageInfoId)!;
+ let propagatedStyles: Set<StylesheetAsset>;
+ if (isContentCollectionCache) {
+ 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);
sheetAddedToPage = true;
diff --git a/packages/astro/test/content-collections.test.js b/packages/astro/test/content-collections.test.js
index 699254991..cee54f82e 100644
--- a/packages/astro/test/content-collections.test.js
+++ b/packages/astro/test/content-collections.test.js
@@ -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', () => {
let json;
before(async () => {
diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js
index 0583ed376..74f86ba7f 100644
--- a/packages/astro/test/core-image.test.js
+++ b/packages/astro/test/core-image.test.js
@@ -1010,7 +1010,7 @@ describe('astro:image', () => {
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();
let request = new Request('http://example.com/');
let response = await app.render(request);
diff --git a/packages/astro/test/fixtures/content-collections/src/pages/propagation.astro b/packages/astro/test/fixtures/content-collections/src/pages/propagation.astro
new file mode 100644
index 000000000..3775697ac
--- /dev/null
+++ b/packages/astro/test/fixtures/content-collections/src/pages/propagation.astro
@@ -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>