Skip to content
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

Merged
merged 25 commits into from Oct 6, 2023

Conversation

harryzcy
Copy link
Contributor

@harryzcy harryzcy commented Sep 17, 2023

Breaking changes

Docusaurus v3 bumps 2 major dependencies related to code syntax highlighting

  • prism-react-renderer v1 => v2
  • react-live v2 => v4

prism-react-renderer v2

The 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 use const customTheme = require('prism-react-renderer/themes/<themeName>');.

But now, prism-react-renderer exports all themes as a single variable themes. So now you would import like the following:

import { themes } from "prism-react-renderer";
const customTheme = themes.github; // or other theme names

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.js

From 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:

const siteConfig = {
  themeConfig: {
    prism: {
      additionalLanguages: ["bash", "diff", "json"],
    }
  }
};

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 v4

Docusaurus 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:

  • v3: swap code transpiler from Bublé to Sucrase, swap internal editor
  • v4: upgrade codebase to TypeScript

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

CleanShot 2023-10-06 at 19 02 20@2x

CleanShot 2023-10-06 at 19 03 58@2x

CleanShot 2023-10-06 at 19 06 21@2x

CleanShot 2023-10-06 at 19 10 05@2x

CleanShot 2023-10-06 at 19 11 14@2x

Test Plan

CI + visual tests

Test links

https://deploy-preview-9316--docusaurus-2.netlify.app/

Related issues/PRs

fix #8940

@netlify
Copy link

netlify bot commented Sep 17, 2023

[V2]

Name Link
🔨 Latest commit bcc6bdf
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65203ceb78e37e0008f8eb68
😎 Deploy Preview https://deploy-preview-9316--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Sep 17, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 73 🟢 97 🟢 92 🟢 100 🟠 89 Report
/docs/installation 🟠 72 🟢 98 🟢 92 🟢 100 🟠 89 Report

@slorber slorber added Argos Add this label to run UI visual regression tests. See argos.yml GH action. pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. labels Sep 19, 2023
Copy link
Collaborator

@slorber slorber left a 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:

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.

examples/classic/package.json Outdated Show resolved Hide resolved
packages/docusaurus-theme-common/package.json Outdated Show resolved Hide resolved
examples/classic/docusaurus.config.js Outdated Show resolved Hide resolved
examples/classic-typescript/docusaurus.config.js Outdated Show resolved Hide resolved
examples/classic-typescript/package.json Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
@harryzcy
Copy link
Contributor Author

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?

@slorber where should this go?

@slorber
Copy link
Collaborator

slorber commented Sep 20, 2023

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?

@slorber where should this go?

I usually put a ## Breaking changes section at the top of each PR with some notes and external ref links.

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:
https://github.com/facebook/docusaurus/releases/tag/v3.0.0-beta.0

@slorber
Copy link
Collaborator

slorber commented Sep 20, 2023

Apparently we have some pages that produce errors now 😅 site can't build in production mode.

CleanShot 2023-09-20 at 16 24 34@2x

Try:

@harryzcy
Copy link
Contributor Author

harryzcy commented Sep 20, 2023

I'll take another look. I can't reproduce it locally for some reason

Edit: reference: PrismJS/prism#1400 (comment)

@slorber slorber added this to the 3.0 milestone Sep 25, 2023
@harryzcy
Copy link
Contributor Author

now I can't reproduce error TS2578: Unused "@ts-expect-error" directive. error locally...

@argos-ci
Copy link

argos-ci bot commented Oct 6, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 🧿 Changes detected (Review) 37 changes Oct 6, 2023, 5:14 PM

@slorber
Copy link
Collaborator

slorber commented Oct 6, 2023

Seems to be working now

But our visual regression tests tool reports many unexpected changes to syntax highlighting:

https://app.argos-ci.com/meta-open-source/docusaurus/builds/247/60618995

Will investigate.
@carloskelly13 any idea what could be happening here?

Comment on lines +29 to +32
if (lang === 'php') {
// eslint-disable-next-line global-require
require('prismjs/components/prism-markup-templating.js');
}
Copy link
Collaborator

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?

Copy link
Contributor Author

@harryzcy harryzcy Oct 6, 2023

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

@slorber
Copy link
Collaborator

slorber commented Oct 6, 2023

Looks like we have weird hydrations issues here:
https://deploy-preview-9316--docusaurus-2.netlify.app/docs/docusaurus-core

Comment on lines 77 to 78
{...defaultProps}
prism={Prism}
Copy link
Collaborator

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.

@slorber slorber changed the title chore: upgrade prism-react-renderer to v2 chore: upgrade prism-react-renderer to v2, react-live to v4 Oct 6, 2023
@slorber slorber changed the title chore: upgrade prism-react-renderer to v2, react-live to v4 chore: upgrade syntax highlighting dependencies, prism-react-renderer to v2, react-live to v4 Oct 6, 2023
@slorber
Copy link
Collaborator

slorber commented Oct 6, 2023

LGTM thanks 🎉 will be in Docusaurus v3

@slorber slorber merged commit dceaae4 into facebook:main Oct 6, 2023
29 of 31 checks passed
@harryzcy harryzcy deleted the prism-react-renderer-v2 branch October 6, 2023 21:28
This was referenced Oct 19, 2023
hieplq added a commit to hieplq/idempiere.github.io that referenced this pull request Mar 29, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Argos Add this label to run UI visual regression tests. See argos.yml GH action. CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for prism-react-renderer v2.0.2
4 participants