docusaurus-search-local icon indicating copy to clipboard operation
docusaurus-search-local copied to clipboard

Upgrade Docusaurus - Enable Docusaurus Faster on website

Open slorber opened this issue 1 year ago โ€ข 9 comments

Docusaurus maintainer here ๐Ÿ‘‹

This is a POC to ensure this plugin is compatible with Docusaurus Faster

I'm not sure how your setup works exactly, not super familiar with Yarn PnP but got some annoying errors due to it ๐Ÿ˜…

I'm able to build with Webpack, but Rspack fails with this error I can't solve when PnP is enabled:

[ERROR] Client bundle compiled with errors therefore further build is impossible. ร— Module not found: Can't resolve '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/.yarn/virtual/@docusaurus-core-virtual-aaf120fccf/0/cache/@docusaurus-core-npm-3.5.2-canary-6122-e777a73518-b778e9de54.zip/node_modules/@docusaurus/core/lib/client/clientEntry.js' in '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/website'

And idea?

Benchmark

Using node modules linker

Cold builds - much faster

hyperfine --prepare 'yarn workspace website clear' --runs 3 'DOCUSAURUS_FASTER=false yarn build:website' 'DOCUSAURUS_FASTER=true yarn build:website'


Benchmark 1: DOCUSAURUS_FASTER=false yarn build:website
  Time (mean ยฑ ฯƒ):     11.864 s ยฑ  0.251 s    [User: 19.999 s, System: 5.471 s]
  Range (min โ€ฆ max):   11.609 s โ€ฆ 12.110 s    3 runs

Benchmark 2: DOCUSAURUS_FASTER=true yarn build:website
  Time (mean ยฑ ฯƒ):      3.139 s ยฑ  0.050 s    [User: 4.666 s, System: 0.862 s]
  Range (min โ€ฆ max):    3.106 s โ€ฆ  3.196 s    3 runs

Summary
  DOCUSAURUS_FASTER=true yarn build:website ran
    3.78 ยฑ 0.10 times faster than DOCUSAURUS_FASTER=false yarn build:website

Warm builds - same:

DOCUSAURUS_FASTER=false yarn build:website
hyperfine --runs 3 'DOCUSAURUS_FASTER=false yarn build:website' 'DOCUSAURUS_FASTER=true yarn build:website'


Benchmark 1: DOCUSAURUS_FASTER=false yarn build:website
  Time (mean ยฑ ฯƒ):      3.031 s ยฑ  0.066 s    [User: 3.602 s, System: 0.539 s]
  Range (min โ€ฆ max):    2.990 s โ€ฆ  3.107 s    3 runs

  Warning: The first benchmarking run for this command was significantly slower than the rest (3.107 s). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.

Benchmark 2: DOCUSAURUS_FASTER=true yarn build:website
  Time (mean ยฑ ฯƒ):      3.120 s ยฑ  0.084 s    [User: 4.671 s, System: 0.859 s]
  Range (min โ€ฆ max):    3.065 s โ€ฆ  3.217 s    3 runs

Summary
  DOCUSAURUS_FASTER=false yarn build:website ran
    1.03 ยฑ 0.04 times faster than DOCUSAURUS_FASTER=true yarn build:website

Summary by CodeRabbit

  • New Features

    • Introduced a new script to clear Docusaurus cache.
    • Added experimental build optimization features.
  • Updates

    • Updated Docusaurus packages to version 3.7.0 for improved performance and features.
    • Added support for a new dependency, @docusaurus/faster.
  • Configuration Changes

    • Updated .gitignore to exclude .idea directory.
    • Modified Yarn configuration to specify package linking method and added package extensions.
    • Introduced new configuration options for experimental build optimizations in Docusaurus configuration files.

slorber avatar Oct 25 '24 14:10 slorber

Walkthrough

This pull request includes updates to several configuration files in the project. The .gitignore file now excludes the .idea directory. The .yarnrc.yml file has been modified to include a new property for package linking and an extension for specific Docusaurus packages. The package.json files for both the main project and the website have updated Docusaurus package versions from 3.6.0 to 3.7.0, with additional scripts and dependencies added in the website's configuration. New experimental features are introduced in the Docusaurus configuration for both the main project and the multi-docs setup.

Changes

File Change Summary
.gitignore - Added entry for .idea to be ignored by Git.
.yarnrc.yml - Added property nodeLinker: node-modules.
- Introduced section packageExtensions for @docusaurus/bundler, @docusaurus/theme-common, terser-webpack-plugin, and css-minimizer-webpack-plugin with respective dependencies.
package.json - Updated resolutions for several Docusaurus packages from 3.6.0 to 3.7.0:
@docusaurus/core, @docusaurus/module-type-aliases, @docusaurus/preset-classic, @docusaurus/theme-classic, @docusaurus/theme-common, @docusaurus/plugin-content-docs.
- Added new entries for @docusaurus/faster and @rspack/core.
website/docusaurus.config.js - Added configuration option: future: { experimental_faster: { swcJsLoader: true, swcJsMinimizer: true, swcHtmlMinimizer: true, lightningCssMinimizer: true, rspackBundler: false, mdxCrossCompilerCache: true } }.
website/package.json - Added script "clear": "docusaurus clear".
- Updated dependency versions for @docusaurus/core, @docusaurus/preset-classic, @docusaurus/theme-classic, and @docusaurus/theme-common from ^3.6.0 to ^3.7.0.
- Added new dependency @docusaurus/faster with version ^3.7.0.
website-multi-docs/docusaurus.config.js - Added configuration section: future: { experimental_faster: { swcJsLoader: true, swcJsMinimizer: true, swcHtmlMinimizer: true, lightningCssMinimizer: true, rspackBundler: false, mdxCrossCompilerCache: true } }.
website-multi-docs/package.json - Updated dependency versions for @docusaurus/core, @docusaurus/plugin-content-docs, @docusaurus/preset-classic, @docusaurus/theme-classic, @docusaurus/theme-common from ^3.6.0 to ^3.7.0.
- Added new dependency @docusaurus/faster with version ^3.7.0.
website/babel.config.js - Removed Babel configuration file.
website-multi-docs/babel.config.js - Removed Babel configuration file.

๐Ÿ“œ Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between ac4af80991f35a6d7d01a72f4beae3577d8ce4cf and 517de29f26a30dc8e84bc29a9090638177f2c054.

โ›” Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
๐Ÿ“’ Files selected for processing (3)
  • package.json (1 hunks)
  • website-multi-docs/package.json (1 hunks)
  • website/package.json (1 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (3)
  • website/package.json
  • website-multi-docs/package.json
  • package.json
โฐ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - easyops-cn-docusaurus-search-local
  • GitHub Check: Header rules - easyops-cn-docusaurus-search-local
  • GitHub Check: Pages changed - easyops-cn-docusaurus-search-local

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

โค๏ธ Share
๐Ÿชง Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Oct 25 '24 14:10 coderabbitai[bot]

Deploy Preview for easyops-cn-docusaurus-search-local ready!

Name Link
Latest commit 517de29f26a30dc8e84bc29a9090638177f2c054
Latest deploy log https://app.netlify.com/sites/easyops-cn-docusaurus-search-local/deploys/67979f60b0b4a20008e66591
Deploy Preview https://deploy-preview-468--easyops-cn-docusaurus-search-local.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.

netlify[bot] avatar Oct 25 '24 14:10 netlify[bot]

๐Ÿ‘ Great work!

I got no idea why it doesn't work with yarn PnP, either. Though using node modules linker works, right? Maybe related to dependencies with canary versions.

weareoutman avatar Oct 28 '24 01:10 weareoutman

I'll try again once v3.6 is out and we'll see

For now it's already nice to have a POC proving that this plugin works with the new bundler :)

slorber avatar Oct 28 '24 08:10 slorber

Docusaurus v3.6 is out: https://docusaurus.io/blog/releases/3.6

PR ready to review (but still fighting with PnP issues)

Unfortunately, the Yarn PnP error remains, and it only builds with node linker. Maybe @arcanis any idea what could cause this error?

[ERROR] Client bundle compiled with errors therefore further build is impossible.
ร— Module not found: Can't resolve '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/.yarn/__virtual__/@docusaurus-core-virtual-22c3351990/0/cache/@docusaurus-core-npm-3.6.0-794aa300d6-d024957005.zip/node_modules/@docusaurus/core/lib/client/clientEntry.js' in '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/website'

Edit, it seems using rspackBundler: false fix that error, and there's a related Rspack issue: https://github.com/web-infra-dev/rspack/issues/2236

slorber avatar Nov 04 '24 13:11 slorber

Looks like Yarn PnP will be solved in Rspack v1.2 soon

https://github.com/web-infra-dev/rspack/pull/7639

slorber avatar Jan 17 '25 10:01 slorber

Hi :wave: not really an issue but I am a little confused...is this PR in order to make the package examples or build work with Faster (IE for the developer), or is it to provide a working plugin for the end-user who is using Faster? I ask because I can build my docusaurus site with Faster, default settings, and this plugin without an issue.

FoxxMD avatar Jan 17 '25 13:01 FoxxMD

This plugin is already compatible, I only turned Docusaurus Faster on the demo website as a proof that this is compatible.

See also my guide for plugins authors: https://github.com/facebook/docusaurus/issues/10572

None of these changes are required for this plugin, as far as I remember.

slorber avatar Jan 17 '25 15:01 slorber

Tried to upgrade this PR but still getting errors when using Rspack + Yarn PnP, while it works fine with Webpack + Yarn PnP

Errors such as:

ร— Cannot find module '@mdx-js/react' for matched aliased key '@mdx-js/react'

ร— Cannot find module 'react' for matched aliased key 'react'

ร— Module not found: Can't resolve './src/standalone/' in '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/.yarn/cache/@easyops-cn-autocomplete.js-npm-0.38.1-2375cf670a-40a053d7fb.zip/node_modules/@easyops-cn/autocomplete.js' โ•ญโ”€[1:0] 1 โ”‚ 'use strict'; ยท โ–ฒ 2 โ”‚ 3 โ”‚ module.exports = require('./src/standalone/'); โ•ฐโ”€โ”€โ”€โ”€

ร— Module not found: Can't resolve './BaseUrlIssueBanner' in '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/.yarn/virtual/@docusaurus-core-virtual-8ba776b5dc/0/cache/@docusaurus-core-npm-3.7.0-64e9676bfa-df07928282.zip/node_modules/@docusaurus/core/lib/client' โ•ญโ”€[18:31] 16 โ”‚ import { DocusaurusContextProvider } from './docusaurusContext'; 17 โ”‚ import PendingNavigation from './PendingNavigation'; 18 โ”‚ import BaseUrlIssueBanner from './BaseUrlIssueBanner'; ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 19 โ”‚ import SiteMetadataDefaults from './SiteMetadataDefaults'; 20 โ”‚ // TODO, quick fix for CSS insertion order โ•ฐโ”€โ”€โ”€โ”€

ร— Module not found: Can't resolve './components/ThemedComponent' in '/Users/sebastienlorber/Desktop/projects/docusaurus-search-local-easyops-cn/.yarn/virtual/@docusaurus-theme-common-virtual-67b7f3254f/0/cache/@docusaurus-theme-common-npm-3.7.0-5d72768bc3-9b27a2c74f.zip/node_modules/@docusaurus/theme-common/lib' โ•ญโ”€[49:43] 47 โ”‚ * APIs to document 48 โ”‚ */ export { useThemeConfig } from './utils/useThemeConfig'; 49 โ”‚ export { default as ThemedComponent } from './components/ThemedComponent'; ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 50 โ”‚ export { createStorageSlot, useStorageSlot, listStorageKeys } from './utils/storageUtils'; 51 โ”‚ export { usePluralForm } from './utils/usePluralForm'; โ•ฐโ”€โ”€โ”€โ”€

Not sure how to troubleshoot these problems but will have to investigate to know if the issues affect only this site/monorepo, or Docusaurus + Rspack in general.

cc @hardfist

slorber avatar Jan 27 '25 15:01 slorber