-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
🤞 phase/openPost is being triaged manuallyPost is being triaged manually
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and discussions and couldn’t find anything (or linked relevant results below)
Problem
TL;DR: The way MDX works fundamentally leads to much slower build and runtime compared to a pure Markdown -> HTML generation.
Current solutions
From how I understand MDX, it works like this:
- On the build side, it takes Markdown and it converts it to React JavaScript (React.createElement), as described in https://mdxjs.com/packages/mdx/#use.
- On the runtime side:
a. The React.createElement is inlined in the Next.js RSC payload
b. React takes the RSC payload and hydrates it (yes Next.js needs to hydrate RSC too, but it's not as costly as client components, see NEXTJS 13: self.__next_f.push vercel/next.js#42170).
This is opposition to tools like marked:
- On the build side, it takes Markdown and converts it to HTML directly.
- On the runtime:
a. The string representation is inlined in the Next.js RSC payload
b. React takes the RSC payload and hydrates it with innerHTML (dangerouslySetInnerHTML).
Now, the problem is that each step seems much slower on the MDX side:
- 1 The step seems x2 slower if we can trust a benchmark like https://github.com/mui/material-ui/tree/v5.x/benchmark/server#muidocs
- 2.a This step adds more data to the .html page because of how heavy the RSC payload is, see NEXTJS 13: self.__next_f.push vercel/next.js#42170 for some context on this. We could benchmark it to +35%: [docs-infra] Add CodeHighlighter component for loading demos and codeblocks mui/mui-public#379 (comment)
- 2.b This step is x2.5 slower as we could benchmark it in [docs-infra] Add CodeHighlighter component for loading demos and codeblocks mui/mui-public#379 (comment).
Proposed solutions
So I wonder if MDX would be interested in supporting a hybrid rendering mode. For example, allowing a header to be either an HTML string output https://marked.js.org/using_pro#renderer, or a React element. My hope is that this could lead to much faster build time (e.g. no need anymore for Rust https://nextjs.org/docs/app/guides/mdx#using-the-rust-based-mdx-compiler-experimental) and much faster render time.
Metadata
Metadata
Assignees
Labels
🤞 phase/openPost is being triaged manuallyPost is being triaged manually