Skip to content

Commit f41ff6d

Browse files
committed
feat: add asyncMode env
1 parent 50149de commit f41ff6d

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

apps/docs/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# https://fumadocs.dev/docs/mdx/async
2+
MDX_ASYNC=
13
EN_DOMAIN=nextjs.im
24
ZH_HANS_DOMAIN=zh-hans.nextjs.im
35
ORAMA_PRIVATE_API_KEY_EN=

apps/docs/source.config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ import { z } from 'zod';
99
import { addMdxContent } from '@/lib/remark-plugins/remark-add-content';
1010
import { convertCodeMeta } from '@/lib/remark-plugins/remark-convert-code-meta';
1111

12+
const asyncMode = process.env.MDX_ASYNC === 'true';
13+
if (!asyncMode && process.env.NODE_ENV === 'development') {
14+
console.log('AsyncMode', asyncMode);
15+
console.warn(
16+
'This may result in longer dev server start time for large docs sites, you can enable Async Mode on doc collections to improve this.',
17+
);
18+
}
19+
1220
const defaultDocsOptions = {
1321
docs: {
14-
async: true,
22+
async: asyncMode,
1523
schema: frontmatterSchema.extend({
1624
nav_title: z.string().optional(),
1725
source: z.string().optional(),
@@ -43,7 +51,6 @@ export const docs_zh_hans = defineDocs({
4351

4452
export default defineConfig({
4553
mdxOptions: {
46-
remarkStructureOptions: false,
4754
remarkPlugins: (v) => [convertCodeMeta, addMdxContent, ...v],
4855
},
4956
});

apps/docs/src/app/[locale]/docs/[[...slug]]/page.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DocsLayout } from '@/components/layout';
2+
import { routing } from '@/i18n/routing';
23
import { type RouterType, routerTypeCookie } from '@/lib/const';
34
import { getPage } from '@/lib/page';
45
import { getDocsLayoutTree, getPageTreePeers } from '@/lib/pageTree';
@@ -15,7 +16,7 @@ import { cookies } from 'next/headers';
1516
import { notFound } from 'next/navigation';
1617

1718
export default async function Docs(props: {
18-
params: Promise<{ locale: Locale; slug?: string[] }>;
19+
params: Promise<{ locale: Locale; slug: string[] }>;
1920
}) {
2021
const routerType = (await cookies()).get(routerTypeCookie)
2122
?.value as RouterType;
@@ -28,16 +29,23 @@ export default async function Docs(props: {
2829
const page = getPage(locale, docUrl);
2930
if (!page) notFound();
3031
const { isApp, isPages } = parseDocId(docId);
31-
// Markdown content requires await
32-
let { body: MdxContent, toc } = await page.data.load();
32+
// @ts-ignore
33+
let { body: MdxContent, toc } = page.data.load
34+
? // @ts-ignore
35+
await page.data.load()
36+
: page.data;
3337

3438
// source: app/getting-started/installation
3539
const ref = page.data.source;
3640
if (ref) {
3741
const refUrl = getDocUrl(ref);
3842
const refPage = getPage(locale, refUrl);
3943
if (!refPage) notFound();
40-
const { body: MdxContent2, toc: toc2 } = await refPage.data.load();
44+
// @ts-ignore
45+
const { body: MdxContent2, toc: toc2 } = refPage.data.load
46+
? // @ts-ignore
47+
await refPage.data.load()
48+
: refPage.data;
4149

4250
MdxContent = MdxContent2;
4351
toc = toc2;

apps/docs/src/lib/remark-plugins/remark-add-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Code, Heading, Paragraph, Root } from 'mdast';
1+
import type { Heading, Paragraph, Root } from 'mdast';
22

33
/**
44
* Remark plugin that adds content to the document based on frontmatter data

0 commit comments

Comments
 (0)