Skip to content

refactor: reduce lodash footprint (follow-up to #1509)#1524

Open
s-lukashenka-micoworks wants to merge 3 commits into
PaloAltoNetworks:mainfrom
s-lukashenka-micoworks:chore/lodash-1509-followups
Open

refactor: reduce lodash footprint (follow-up to #1509)#1524
s-lukashenka-micoworks wants to merge 3 commits into
PaloAltoNetworks:mainfrom
s-lukashenka-micoworks:chore/lodash-1509-followups

Conversation

@s-lukashenka-micoworks

Copy link
Copy Markdown

Summary

Follow-up to the discussion in #1509. That issue proposed swapping lodash for es-toolkit; @sserrata closed it in favor of three lower-risk steps and noted PRs for items 1–3 would be welcome. This PR implements all three.

Each item is a separate commit so they can be reviewed (or dropped) independently:

  1. build(deps): bump lodash to ^4.18.1 — picks up the security patches released in the lodash 4.18.x line.
  2. refactor: replace lodash find/flatten/uniq/isEmpty with native JS — removes the four utilities that have direct native equivalents:
    • uniq[...new Set(...)] (openapi.ts, sidebars/index.ts)
    • flattenArray.prototype.flat() (DiscriminatorTabs, SchemaTabs)
    • findArray.prototype.find() (languages.ts)
    • isEmptyObject.keys(x).length === 0 (createSchema.ts, Schema)
  3. refactor: use lodash subpath import for kebabCase in sidebars — switches the one remaining barrel import (import { kebabCase } from "lodash") to the subpath form so the rest of lodash can be tree-shaken. Every other lodash usage already imports from a subpath.

The remaining lodash utilities (merge, mergeWith, cloneDeep, kebabCase, unionBy) are kept and could be vendored later (item 4) if the project wants to drop the dependency entirely.

Notes on correctness

  • The two isEmpty call sites are both guarded by a preceding truthiness check (if (!additionalProperties) return ...), so the value is always a non-null object at the call — Object.keys(x).length === 0 is equivalent there.
  • The find replacement keeps optional chaining (arr1?.find(...)) to preserve lodash's tolerance of a nullish collection.
  • lodash.flatten flattens a single level, which matches Array.prototype.flat()'s default depth of 1.

Testing

  • yarn build (tsc) passes for both docusaurus-plugin-openapi-docs and docusaurus-theme-openapi-docs.
  • All test suites covering the changed files pass (sidebars, languages, openapi, webhooks).
  • One unrelated suite (createSchema.test.ts) fails, but it fails identically on a clean main checkout (an allof-merge issue) — it is not affected by these changes.

🤖 Generated with Claude Code

Siarhei Lukashenka and others added 3 commits June 25, 2026 09:32
Picks up the security patches released in lodash 4.18.x (4.18.0/4.18.1).
Addresses item 1 of the follow-ups discussed in PaloAltoNetworks#1509.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drops the dependency on four lodash utilities that have direct native
equivalents:
- uniq    -> [...new Set(...)]   (openapi.ts, sidebars/index.ts)
- flatten -> Array.prototype.flat (DiscriminatorTabs, SchemaTabs)
- find    -> Array.prototype.find (languages.ts)
- isEmpty -> Object.keys(x).length === 0 (createSchema.ts, Schema)

The isEmpty call sites are guarded by a preceding truthiness check, so
the value is always a non-null object there. The find call keeps optional
chaining to preserve lodash's null-tolerance.
Addresses item 2 of the follow-ups discussed in PaloAltoNetworks#1509.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Switches the one remaining barrel import (import { kebabCase } from
"lodash") to the subpath form (import kebabCase from "lodash/kebabCase")
so tree shaking can drop the rest of lodash. All other lodash usage in
the codebase already uses subpath imports.
Addresses item 3 of the follow-ups discussed in PaloAltoNetworks#1509.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant