diff options
author | 2022-08-05 17:16:34 -0500 | |
---|---|---|
committer | 2022-08-05 17:16:34 -0500 | |
commit | 9afa4611cbddd14349dcad9bf0af1fb8b9585381 (patch) | |
tree | cc47014f2db46062d90d21ca158338e48d75258b | |
parent | c56a9227c717480ef4cf25cd50634872ef021101 (diff) | |
download | astro-9afa4611cbddd14349dcad9bf0af1fb8b9585381.tar.gz astro-9afa4611cbddd14349dcad9bf0af1fb8b9585381.tar.zst astro-9afa4611cbddd14349dcad9bf0af1fb8b9585381.zip |
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>
-rw-r--r-- | .changeset/strong-cars-wash.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/render/core.ts | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/.changeset/strong-cars-wash.md b/.changeset/strong-cars-wash.md new file mode 100644 index 000000000..6dc8926d7 --- /dev/null +++ b/.changeset/strong-cars-wash.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix issue when using Fragment inside MDX diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 231088fa7..6c47d0a18 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -10,7 +10,7 @@ import type { } from '../../@types/astro'; 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 { createResult } from './result.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') { 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); } |