-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: upgrade syntax highlighting dependencies, prism-react-renderer
to v2, react-live
to v4
#9316
Conversation
The `prism` prop for Hightlight is declared as optional, but omitting it gives errors. So it's now passed in.
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
That's a good idea to do this upgrade for Docusaurus v3
We'll also have to update the docs as well:
- https://docusaurus.io/docs/next/markdown-features/code-blocks
- https://docusaurus.io/docs/next/api/themes/configuration
We'll also want to upgrade react-live to avoid a duplicate prism version. React-Live v4 uses prism-react-renderer v2
https://github.com/FormidableLabs/react-live
Supersed this PR: #6589
Also we'll need some notes to explain users how to handle this breaking change. Can you write down some notes to explain what users should do when upgrading, and link to relevant external resources explaining breaking changes in depth?
Also related but apparently react-live upgrade breaks SSR support, and regression is still not fixed today (cf #6246 (comment)). Is it safe to upgrade or can it annoy our users? 🤷♂️ We need to study that. I think it should be fine because afaik we SSR a "loading..." placeholder for the preview, and bypass SSR for now.
@slorber where should this go? |
I usually put a This makes it easier to aggregate all those notes into the final v3.0 blog post on release. It doesn't have to be super polished but please note down things that we might have forgotten in a few weeks, and that Docusaurus users should be aware of when upgrading ;) Links to upgraded packages release notes and breaking change docs can be useful for example. See for example PRs listed in v3 beta: |
I'll take another look. Edit: reference: PrismJS/prism#1400 (comment) |
if (lang === 'php') { | ||
// eslint-disable-next-line global-require | ||
require('prismjs/components/prism-markup-templating.js'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering why do we need this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it's not an issue previously, but the error is mentioned here: PrismJS/prism#1400 (comment). Without it, there's a TypeError: Cannot read property 'tokenizePlaceholders' of undefined
Looks like we have weird hydrations issues here: |
{...defaultProps} | ||
prism={Prism} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the issue, we used the "vendored prism library" and should keep using it so passing a prism instance is not needed now. I'll remove it.
prism-react-renderer
to v2prism-react-renderer
to v2, react-live
to v4
prism-react-renderer
to v2, react-live
to v4prism-react-renderer
to v2, react-live
to v4
LGTM thanks 🎉 will be in Docusaurus v3 |
1. remove package-lock.json => reason package-lock.json is an automatically generated file that stores dependency information. This ensures a faster build process by eliminating the need to resolve dependencies every time you build your project 2. remove src/theme/SearchBar by https://github.com/praveenn77/docusaurus-lunr-search?tab=readme-ov-file#upgrading-from-docusaurus-v2-to-v3 3. update prismThemes by facebook/docusaurus#9316
1. remove package-lock.json => reason package-lock.json is an automatically generated file that stores dependency information. This ensures a faster build process by eliminating the need to resolve dependencies every time you build your project 2. remove src/theme/SearchBar by https://github.com/praveenn77/docusaurus-lunr-search?tab=readme-ov-file#upgrading-from-docusaurus-v2-to-v3 3. update prismThemes by facebook/docusaurus#9316
Breaking changes
Docusaurus v3 bumps 2 major dependencies related to code syntax highlighting
prism-react-renderer
v1 => v2react-live
v2 => v4prism-react-renderer
v2The
prism-react-renderer
v2 release notes are not super exhaustive, but there are 2 major changes to be aware of for Docusaurus users.Theme API
The API for
prism-react-renderer
is changed. Previously, to import a theme, you would useconst customTheme = require('prism-react-renderer/themes/<themeName>');
.But now,
prism-react-renderer
exports all themes as a single variablethemes
. So now you would import like the following:Default languages
Previously,
react-prism-render
included more languages by default: https://github.com/FormidableLabs/prism-react-renderer/blob/v1.3.5/src/vendor/prism/includeLangs.jsFrom v2+, less languages are included: https://github.com/FormidableLabs/prism-react-renderer/blob/prism-react-renderer%402.1.0/packages/generate-prism-languages/index.ts#L9
You may need to add the languages you need to the Docusaurus config:
Reminder: the list of languages supported by prism: https://prismjs.com/#supported-languages
Note: make sure to restart the Docusaurus dev server after adding a language, or you'll get a console error:
runtime~main.js:39 Uncaught Error: Cannot find module './prism-scss'
react-live
v4Docusaurus upgrades
react-live
from v2 to v4. This shouldn't affect much Docusaurus users but newer versions might have new useful features to check.Major version release notes:
Motivation
Upgrade major code syntax highlighting libraries to be on newer versions and have access to latest features.
Some code blocks will have improved highlighting for free.
For example, on the Docusaurus websites our visual regression tests noticed those improvements: https://app.argos-ci.com/meta-open-source/docusaurus/builds/249
Test Plan
CI + visual tests
Test links
https://deploy-preview-9316--docusaurus-2.netlify.app/
Related issues/PRs
fix #8940