mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Support Fragment in MDX files (#4136)
* fix: Fragment for MDX files * Update core.ts * fix: better type guard for `render` Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
parent
c56a9227c7
commit
9afa4611cb
2 changed files with 11 additions and 1 deletions
5
.changeset/strong-cars-wash.md
Normal file
5
.changeset/strong-cars-wash.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix issue when using Fragment inside MDX
|
|
@ -10,7 +10,7 @@ import type {
|
||||||
} from '../../@types/astro';
|
} from '../../@types/astro';
|
||||||
import type { LogOptions } from '../logger/core.js';
|
import type { LogOptions } from '../logger/core.js';
|
||||||
|
|
||||||
import { renderPage } from '../../runtime/server/index.js';
|
import { renderPage, Fragment } from '../../runtime/server/index.js';
|
||||||
import { getParams } from '../routing/params.js';
|
import { getParams } from '../routing/params.js';
|
||||||
import { createResult } from './result.js';
|
import { createResult } from './result.js';
|
||||||
import { callGetStaticPaths, findPathItemByKey, RouteCache } from './route-cache.js';
|
import { callGetStaticPaths, findPathItemByKey, RouteCache } from './route-cache.js';
|
||||||
|
@ -157,6 +157,11 @@ export async function render(opts: RenderOptions): Promise<Response> {
|
||||||
if (typeof (mod as any).components === 'object') {
|
if (typeof (mod as any).components === 'object') {
|
||||||
Object.assign(pageProps, { components: (mod as any).components });
|
Object.assign(pageProps, { components: (mod as any).components });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: expose `Fragment` for all MDX components
|
||||||
|
if (typeof mod.default === 'function' && mod.default.name.startsWith('MDX')) {
|
||||||
|
Object.assign(pageProps, { components: Object.assign((pageProps?.components as any) ?? {}, { Fragment }) });
|
||||||
|
}
|
||||||
|
|
||||||
return await renderPage(result, Component, pageProps, null, streaming);
|
return await renderPage(result, Component, pageProps, null, streaming);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue