Skip to content

refactor(create-docusaurus): replace lodash with native implementation#11653

Merged
slorber merged 2 commits intofacebook:mainfrom
torresgol10:refactor/remove-lodash-create-docusaurus
Jan 22, 2026
Merged

refactor(create-docusaurus): replace lodash with native implementation#11653
slorber merged 2 commits intofacebook:mainfrom
torresgol10:refactor/remove-lodash-create-docusaurus

Conversation

@torresgol10
Copy link
Contributor

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

The goal of this PR is to remove the lodash dependency from the create-docusaurus package to reduce the install size and improve startup performance.

Impact:

  • Install Size: Saves ~1.4 MB in node_modules for creating a new site.
  • Startup Time: Improves startup time by ~38ms (avoiding large require('lodash') overhead).
  • Network: Reduces download size by ~315 kB (gzipped).

Changes included:

  • Removed lodash dependency from create-docusaurus/package.json.
  • Replaced _.sortBy with native Array.prototype.sort in create-docusaurus.
  • Replaced _.kebabCase with a robust native implementation.
  • Moved the kebabCase utility to @docusaurus/utils (src/jsUtils.ts) to verify it with tests and allow reuse across the monorepo for future refactors.

Note: If this approach is approved, I plan to continue removing lodash usage incrementally from other packages in future PRs, replacing them with native equivalents or smaller libraries where appropriate.

Test Plan

I verified that the create-docusaurus package builds and runs correctly without lodash.

  1. Unit Tests: Added comprehensive tests for kebabCase in @docusaurus/utils to verify it mimics Lodash's behavior exactly (including edge cases).
    yarn jest packages/docusaurus-utils/src/__tests__/jsUtils.test.ts -t "kebabCase"
  2. Build: Verified create-docusaurus compiles successfully.
    yarn workspace create-docusaurus build

Test links

N/A (Changes affect the CLI tool and Utils, no UI changes).

Deploy preview: N/A

Related issues/PRs

@meta-cla
Copy link

meta-cla bot commented Jan 9, 2026

Hi @torresgol10!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link

netlify bot commented Jan 9, 2026

[V2]

Name Link
🔨 Latest commit 0fdc254
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/697254534413e100089f09f4
😎 Deploy Preview https://deploy-preview-11653--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 project configuration.

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Jan 9, 2026
@meta-cla
Copy link

meta-cla bot commented Jan 9, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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.

Ok to remove the dependency, but I'll rework your PR to make it more acceptable

// TODO remove dependency on large @docusaurus/utils
// would be better to have a new smaller @docusaurus/utils-cli package
import {askPreferredLanguage} from '@docusaurus/utils';
import {askPreferredLanguage, kebabCase} from '@docusaurus/utils';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the TODO, we want to remove the dependency on this package

* Converts a string to kebab-case.
* Mimics lodash's behavior.
*/
export function kebabCase(str: string): string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a reliable kebabCase implementation (compared to Lodash), so we clearly don't want to expose it as a js util to use everywhere else. The Lodash implementation remains better, and this good-enough implementation can stay within the create-docusaurus package.

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.

Ok to remove the dependency, but I'll rework your PR to make it more acceptable

@slorber slorber added the pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. label Jan 22, 2026
@socket-security
Copy link

@slorber slorber merged commit dc0da34 into facebook:main Jan 22, 2026
39 of 45 checks passed
@torresgol10 torresgol10 deleted the refactor/remove-lodash-create-docusaurus branch January 22, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants