Markdown/MDX blog with getStaticProps
#15160
jensmeindertsma
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to use the blog-starter example. This example as well as all CMS examples use
getStaticProps
to fetch Markdown from a CMS / the file system. This is a lot of data, and it's completely static. When usinggetStaticProps
, this data gets inserted into the__NEXT_DATA__
script on the page for rehydration. I understand why this is needed, and I understand it might not be an issue if your page fetches little data.But, Markdown is not React components. Its simply static HTML. This gets passed to the page by
getStaticProps
and is rendered as-is, with just CSS applied. Why does this need to be stored in__NEXT_DATA__
? It doubles the size of my page because the content is not just rendered in the body, it is also stored inside the script.Is there a better way to fetch a lot of text/Markdown/MDX in Next.js at build time, that doesn't have this limitation?
For example, I looked into using
next-mdx-remote
to load my MDX blog posts at build time, so I could usegetStaticProps
on a dynamic page, this makes a shared layout with MDX way easier and cleaner. But, then I discovered that this rendered MDX also exists inside the__NEXT_DATA__
, which almost doubles the page size. However, when I just render my MDX file as page using@next/mdx
,__NEXT_DATA__
doesn't contain the whole page, the page is still static, and it works just fine. The only reason for me not to use@next/mdx
is because it doesn't support shared layouts, and it doesn't support importing frontmatter ( meta data about each MDX file ) from all files in a directory. Next.js prominently advocates that it works great with MDX, but I don't find this to be the case. It's still way too hard to set up a blog with Next.js and MDX. If anyone shares this opinion and has an idea, please share it! I'd love for the Next.js maintainers to share their opinion on MDX with Next.js ( I just don't want to burden them ), and perhaps we could together create a great example for a MDX blog!Please tell me your thoughts on this!
Beta Was this translation helpful? Give feedback.
All reactions