mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
Improve MDX glob perf - move Layout to async import (#4428)
* fix: move layout to async import * chore: changeset * docs: clarify async import
This commit is contained in:
parent
c8d0fa4c4e
commit
a2414bf59e
2 changed files with 11 additions and 2 deletions
5
.changeset/kind-onions-reply.md
Normal file
5
.changeset/kind-onions-reply.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/mdx': patch
|
||||
---
|
||||
|
||||
Fix dev server reload performance when globbing from an MDX layout
|
|
@ -20,13 +20,17 @@ export function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any
|
|||
jsToTreeNode(`export const ${EXPORT_NAME} = ${JSON.stringify(frontmatter)};`),
|
||||
];
|
||||
if (frontmatter.layout) {
|
||||
// NOTE(bholmesdev) 08-22-2022
|
||||
// Using an async layout import (i.e. `const Layout = (await import...)`)
|
||||
// Preserves the dev server import cache when globbing a large set of MDX files
|
||||
// Full explanation: 'https://github.com/withastro/astro/pull/4428'
|
||||
exportNodes.unshift(
|
||||
jsToTreeNode(
|
||||
/** @see 'vite-plugin-markdown' for layout props reference */
|
||||
`import { jsx as layoutJsx } from 'astro/jsx-runtime';
|
||||
import Layout from ${JSON.stringify(frontmatter.layout)};
|
||||
|
||||
export default function ({ children }) {
|
||||
export default async function ({ children }) {
|
||||
const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
|
||||
const { layout, ...content } = frontmatter;
|
||||
content.file = file;
|
||||
content.url = url;
|
||||
|
|
Loading…
Reference in a new issue