Skip to content

refactor: replace lodash/cloneDeep with native structuredClone#218

Open
andrerfneves wants to merge 1 commit into
mainfrom
maintenance/replace-lodash-structured-clone-20260625
Open

refactor: replace lodash/cloneDeep with native structuredClone#218
andrerfneves wants to merge 1 commit into
mainfrom
maintenance/replace-lodash-structured-clone-20260625

Conversation

@andrerfneves

Copy link
Copy Markdown
Owner

Summary

Replaces the single usage of lodash/cloneDeep in src/lib/bolt11.js with the native structuredClone() API, and removes lodash from package.json dependencies.

Why

lodash was a 4.9 MB production dependency used only for two cloneDeep calls in bolt11.js (the sign() and encode() functions). Both functions clone plain JS objects/arrays, which structuredClone() handles correctly:

  • inputPayReqObj — a plain Bolt11 payment request object with properties like complete, paymentRequest, payeeNodeKey, tags, etc.
  • inputData — a plain data object for encoding with properties like coinType, timestamp, signature, etc.

Native structuredClone() has been available in all major browsers since 2022 and Node.js since v17, well within the project's browserslist targets.

Changes

  • src/lib/bolt11.js: Removed import cloneDeep from 'lodash/cloneDeep' and replaced both cloneDeep() calls with structuredClone()
  • package.json: Removed the lodash dependency entry
  • package-lock.json: Updated automatically by npm install

Test Plan

  • All 52 existing tests pass
  • Production build succeeds
  • Bundle size reduced: 1,813.88 kB → 1,777.73 kB (saves ~36 kB, ~8 kB gzipped)

- Replace lodash/cloneDeep usage in bolt11.js with native structuredClone()
- Remove lodash from package.json dependencies
- Bundle size reduced by ~36 KB (1,813.88 kB → 1,777.73 kB)
- structuredClone() is supported in all modern browsers and Node.js 17+
@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lightning-decoder Ready Ready Preview, Comment Jun 25, 2026 10:04pm

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eb29d58d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/bolt11.js
function encode (inputData, addDefaults) {
// we don't want to affect the data being passed in, so we copy the object
let data = cloneDeep(inputData)
let data = structuredClone(inputData)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve Buffer instances when cloning encode input

When callers pass Buffer-valued fields to encode(), structuredClone() converts them into plain Uint8Arrays instead of preserving Buffer instances. That regresses inputs the existing code accepts: for example routing_info.short_channel_id as a Buffer now reaches the later shortId instanceof Buffer validation and is rejected, and a Buffer payeeNodeKey is serialized with Uint8Array#toString('hex') as comma-separated bytes rather than hex. cloneDeep preserved Buffers, so these valid encode inputs now fail or produce malformed output.

Useful? React with 👍 / 👎.

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