-
Notifications
You must be signed in to change notification settings - Fork 100
Bug when using MDXRenderer + Large Markdown Files + PrismJS #411
Comments
What I tried next:
Project still runs! So one would assume it's not related to MDX.
Project shows same Babel output as seen above. So I thought PrismJS would be the problem. But then I tried my long read blog post in https://github.com/gatsbyjs/gatsby-starter-blog and added PrismJs there again. No Babel output. I even made the blog post 4 times longer and it continued to work. So the problem must be related to PrismJS which is used within MDX. If MDX is not there, PrismJS performs well. @ChristopherBiscardi would it be possible to find the culprit within gatsby-mdx (see error output above) or is this related to MDX core? Any help would be super much appreciated! |
Forget the last comment... It works in the MDX starter (except for the Babel 500kb output still showing up). Somehow it only happens because I am using |
Thank you for the detailed bug report and updates! I'm gonna dive into this a bit today and see what I can dig up. My initial hunch for the Babel warning is the HTML that The crashing is much more concerning to me.
We'll find a fix! ❤️ |
Yes. I think PrismJS blows it up in the end. If I output everything that goes through MDXRenderer, I get large pieces of [0] and it comes out as 802kb string [1]. If I remove several PrismJS line highlights, it's possible to render it again.
❤️ I am there to help as well if I can do anything! Didn't dive too much into Babel's implementation details yet though 😅 Thank you so much for digging into this. Didn't expect this to be a blocker, but perhaps it's good to have an edge case like this to work on. This will fix any "large markdown file"-issue for future generations 😄 [1] [0]
|
As a quick update I've been able to track down where things go wrong. It's indeed a bug in So, I'm going to start work on a Babel plugin to address this issue. I should, hopefully, have something together soon!
Yep! There are a few things all coming together to cause this edge case to happen, but now we can fix it for good. Thanks for your patience and understanding. |
I've got a PR open in Gatsby to fix the error. Though I'm also noticing that the actual code blocks are also missing proper whitespace formatting: I'm wondering if this also has to do with babel deopting? Something to also consider @rwieruch is to use |
Again, wow! If there is anything I can do for you @johno just let me know. Your effort on this made my day and surely my next week, because I can migrate all the content to my Gatsby blog now 🎉 Thanks to @ChristopherBiscardi as well for this neat Gatsby to MDX bridge ❤️ Regarding your hint: I will give this example a shot in my code. Haven't seen this approach before! Super valuable. Do I understand correctly that I keep the gatsby-remark-prismjs + MDXRenderer component, but simply define my custom Highlight components for |
Will do <3
Radical! If you ever get a chance I'd love to read a post on the good and bad of your migration (when you complete it) so we can improve upon it. 😸
Using this approach you can remove the It's a bit of a bizarre departure from traditional Markdown-style plugins but is more idiomatic for React and composition as a whole. Best of luck, and please do reach out if you encounter any other questions/issues. |
For very large MDX documents babel will deopt styling. This results in variations in whitespace that can't be handled by the original regex for stripping the export keyword. This replaces that functionality with a plugin. - ChristopherBiscardi/gatsby-mdx#411 - https://github.com/mdx-js/mdx#618
…5452) For very large MDX documents babel will deopt styling. This results in variations in whitespace that can't be handled by the original regex for stripping the export keyword. This replaces that functionality with a plugin. - ChristopherBiscardi/gatsby-mdx#411 - https://github.com/mdx-js/mdx#618
After a patch in mdx-js/mdx#622 it looks like everything in your edge case is addressed @rwieruch! Thanks for your patience and the thorough report with reproduction. 🎉 Git diff of your reproduction repo
|
Perfect! Thank you so much @johno for investing your time here. I settled on your recommended solution now :) |
Hey guys, Is this problem really resolved? It seems that I have exactly the same one while using the latest possible packages. The difference might be that I am working with really long MDX files - thousands of lines and that the number of these files is around 2K (still growing) and I cannot get rid off this:
Being displayed many, many, many times during the build. Is it possible that the merged solution does not count with so many (and big) files? |
@Mrazator the warning you're seeing doesn't substantially impact the operation of mdx or gatsby-mdx, it's just telling you that newlines and whitespace are being omitted. The original issue here was due to the crashing behavior which has since been fixed. Also, this repo is no longer the right place to file issues. Please file gatsby-plugin-mdx issues on the gatsby repo: https://github.com/gatsbyjs/gatsby it's possible that mdx should enable |
@ChristopherBiscardi +1 for always setting |
The last half a year I tinkered on a new blog written with Gatsby to get rid of my Hugo website generator. Since it is a technical blog, I used PrismJs and MDX. Now I am finally in the process of bringing all my content over, but hit a roadblock when I introduced my first blog post in Gatsby which is very long.
TLDR: Large markdown files with MDX (EDIT: and PrismJS) bring Gatsby to crash.
Problem
It all started with the following output on the command line during
gatsby develop
:It can be seen several times during the process of starting the website.
When I visit the website, I see the this output on the screen.
If I open the developer tools console, I see this output multiple times:
Reproduction
I tried to copy and paste the blog post's content into different starter packs until I narrowed it down to MDX. For instance, it works in gatsby-starter-blog. However, when I tried to use it in my gatsby-MDX-starter-blog, it crashes again; the same way like for my new Gatsby blog.
I started a branch for my gatsby-MDX-starter-blog project to have a minimal reproduction of the bug.
In order to exclude styled-components as troublemaker (see Deploying to Netlify Stuck gatsbyjs/gatsby#15205 (comment)), I removed it in this commit on the branch.
Then I started to introduce the long blog post (commit), but not everything, to keep it still without the bug. It still works.
I introduced the remaining parts of the blog post (commit) which leads to the bug. Not sure whether there is a clear threshold so that it breaks for everyone the same, but it breaks after more than 1590 lines in markdown.
How to fix it?
I tried to use https://www.gatsbyjs.org/packages/gatsby-plugin-no-sourcemaps/ out of desperation, but it didn't help.
I set NODE_OPTIONS=--max_old_space_size=4096 but it didn't help.
I removed styled-components (see Reproduction 1), but it didn't help.
I tried to remove MDX, it helped, but I would want to keep it.
Any help is super much appreciated, because I have the feeling that 6 months of work for my new blog with Gatsby went down for nothing, since I struggle with the problem for the last 24 hours. Really appreciate all the things that are possible with MDX now. Hopefully we can find a fix for it. 👍
My Dependencies
The text was updated successfully, but these errors were encountered: