Should I use evaluate
on the client to render statically served MDX? (v2)
#1797
-
I'm building a docs site with Next.js, and I want to statically generate as much as possible. The site will contain a number of pages with MDX content. All pages will have a shared layout that contains a nav with links to all pages that exist. Seems like a common use-case to me. I'm looking at different ways of doing this:
This uses a Webpack loader to transform
Does not support MDX v2 yet. I want to use MDX v2 because one of the remark plugins I use depends on the
What I'm imagining is to use Does anyone have a similar use-case and willing to share their solution? Or perhaps some general knowledge of MDX that you think might help to understand the problem better? Please let me know! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi Nimo! As you mention The folks from I think what you’re looking for is pre-compiling MDX on the server and running it on the client. Tools like Based on your last idea, I’d say: A different solution, with just xdm/MDX 2, is to compile to More on |
Beta Was this translation helpful? Give feedback.
-
I'm sticking with While the remote library hasn't fully caught up yet, most plugins does somehow work if you ask typescript nicely to simply ignore typing errors for now:
The syntax differences between v1 and v2 aren't that different enough to completely break things yet. This builds and compile fine on my current iteration on NextJS v12: "@mdx-js/mdx": "^2.0.0-rc.1",
"@mdx-js/react": "^2.0.0-rc.1",
"next": "^12.0.1",
"next-mdx-remote": "^3.0.5",
"rehype-sanitize": "^5.0.0",
"remark-gfm": "^3.0.1", |
Beta Was this translation helpful? Give feedback.
Hi Nimo!
As you mention
evaluate
, which is a (very nice, IMO) v2 feature, I’d recommend not using@next/mdx
now, as it is on v1. If you have the chance and working on something new, I’d recommend starting with MDX 2.The folks from
next-mdx-remote
are working on MDX v2 support. It’s not there yet.I think what you’re looking for is pre-compiling MDX on the server and running it on the client. Tools like
mdx-bundler
can do that. It’s also something that React Server Components (RSC) does, which is used on the v2 website, but extremely experimental, though I’m mentioning it here because it will solve some of what you’re currently trying to solve.Based on your last idea, I’d say: A differen…