fix: Dynamically import React Syntax Highlighter #1909
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1242
Dynamically imports React Syntax Highlighter and uses the correct theme for the highlight.js based highlighter
Screenshots
Additional Context
This moves a fair bit of
react-syntax-highlighterstuff that was present inside the_appbundle and by dynamically importing the highlight.js based highlighter we can highlight stuff again while preventing over 0.7~1.5 MB of base bundle growth, lazy loading it instead.1To avoid disrupting the already established Markdown parser,
Codedynamically imports libraries when called instead of dynamically importingCodeitselfNoting that #1606 seems to have an alternative package that is much smaller than
RSH, it shouldn't imports 1.5 MB of highlight.js like RSH doChecklist
Are your changes backwards compatible? Please answer below:
Yes
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7, tested with javascript, java, python
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
Did you introduce any new environment variables? If so, call them out explicitly here:
Bundle Analysis
First load JS

Before
After

New NextJS chunk, loaded when there's a code block (see additional context)

Footnotes
this 1.5 MB of growth is not present in the actual code because syntax highlighting isn't enabled ↩