mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
fix: correctly handle head propagation in content layer deferred rendering (#12014)
* chore: run MDX tests against content layer * Handle head propagation in deferred rendering * Add changeset * Update test
This commit is contained in:
parent
8214114a90
commit
53cb41e30e
11 changed files with 41 additions and 18 deletions
5
.changeset/beige-points-search.md
Normal file
5
.changeset/beige-points-search.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue where component styles were not correctly included in rendered MDX
|
|
@ -445,13 +445,12 @@ export async function renderEntry(
|
|||
try {
|
||||
// @ts-expect-error virtual module
|
||||
const { default: contentModules } = await import('astro:content-module-imports');
|
||||
const module = contentModules.get(entry.filePath);
|
||||
const deferredMod = await module();
|
||||
return {
|
||||
Content: deferredMod.Content,
|
||||
headings: deferredMod.getHeadings?.() ?? [],
|
||||
remarkPluginFrontmatter: deferredMod.frontmatter ?? {},
|
||||
};
|
||||
const renderEntryImport = contentModules.get(entry.filePath);
|
||||
return render({
|
||||
collection: '',
|
||||
id: entry.id,
|
||||
renderEntryImport,
|
||||
});
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line
|
||||
console.error(e);
|
||||
|
|
|
@ -82,12 +82,12 @@ export function astroContentVirtualModPlugin({
|
|||
const [, query] = id.split('?');
|
||||
const params = new URLSearchParams(query);
|
||||
const fileName = params.get('fileName');
|
||||
let importerPath = undefined;
|
||||
let importPath = undefined;
|
||||
if (fileName && URL.canParse(fileName, settings.config.root.toString())) {
|
||||
importerPath = fileURLToPath(new URL(fileName, settings.config.root));
|
||||
importPath = fileURLToPath(new URL(fileName, settings.config.root))
|
||||
}
|
||||
if (importerPath) {
|
||||
return await this.resolve(importerPath);
|
||||
if (importPath) {
|
||||
return await this.resolve(`${importPath}?${CONTENT_RENDER_FLAG}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ describe('Head injection w/ MDX', () => {
|
|||
integrations: [mdx()],
|
||||
// test suite was authored when inlineStylesheets defaulted to never
|
||||
build: { inlineStylesheets: 'never' },
|
||||
experimental: { contentLayer: true }
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
import { getEntryBySlug } from 'astro:content';
|
||||
import { getEntry, render } from 'astro:content';
|
||||
|
||||
const launchWeek = await getEntryBySlug('blog', 'using-mdx');
|
||||
const { Content } = await launchWeek.render();
|
||||
const launchWeek = await getEntry('blog', 'using-mdx');
|
||||
const { Content } = await render(launchWeek);
|
||||
---
|
||||
|
||||
<Content />
|
||||
|
|
18
packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/config.ts
vendored
Normal file
18
packages/integrations/mdx/test/fixtures/css-head-mdx/src/content/config.ts
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { defineCollection } from "astro:content";
|
||||
import { glob } from "astro/loaders"
|
||||
|
||||
const posts = defineCollection({
|
||||
loader: glob({
|
||||
pattern: "*.mdx",
|
||||
base: "src/data/posts",
|
||||
})
|
||||
});
|
||||
|
||||
const blog = defineCollection({
|
||||
loader: glob({
|
||||
pattern: "*.mdx",
|
||||
base: "src/data/blog",
|
||||
})
|
||||
});
|
||||
|
||||
export const collections = { posts, blog };
|
|
@ -1,17 +1,17 @@
|
|||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import { getCollection, render } from 'astro:content';
|
||||
import SmallCaps from '../../components/SmallCaps.astro';
|
||||
import Layout from '../../layouts/ContentLayout.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const entries = await getCollection('posts');
|
||||
return entries.map(entry => {
|
||||
return {params: { post: entry.slug }, props: { entry },
|
||||
}});
|
||||
return { params: { post: entry.id }, props: { entry }};
|
||||
});
|
||||
}
|
||||
|
||||
const { entry } = Astro.props;
|
||||
const { Content } = await entry.render();
|
||||
const { Content } = await render(entry);
|
||||
---
|
||||
<Layout title="">
|
||||
<Content components={{ SmallCaps }} />
|
||||
|
|
Loading…
Add table
Reference in a new issue