published fresh until

Lodash: choose shallow assignment or recursive merge

Summary Use a fresh destination, choose whole-section replacement or recursive combination, and override array merging when replacement is required. Start with _.mergeWith

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: pass a fresh destination to _.assign or _.merge, then decide whether nested objects and arrays should replace whole sections or combine recursively.

Short answer

As of November 2026, the release listing identifies Lodash 4.18.1. _.assign copies own enumerable string keyed source properties to the destination (assign source); _.merge recursively merges own and inherited enumerable string keyed properties (merge reference).

Choose / don't choose

  • _.assign: choose when a later configuration section replaces an earlier section entirely.
  • _.merge: choose when missing nested fields should retain defaults.
  • Customizer return: choose when nested objects merge but source arrays replace; don't return undefined for an array you intend to replace, because merging is then handled by the method (customizer contract).

Not for: reducing a JavaScript dependency bundle; see vite-react-bundle-too-large-find-and-cut-production-javascript.

Settings that matter

Setting or flagValue / defaultApplies toSource
Source propertiesUse {} as fresh destination; own enumerable string keyed source properties are assigned to the destination4.18.1assign source
_.merge(object, sources)Use {} as destination for ordinary configuration data; plain objects and arrays combine recursively; later sources win at visited properties4.18.1docs, array handling
customizerFor an array srcValue, return _.cloneDeep(srcValue); if customizer returns undefined, merging is handled by the method4.18.1; application array-replacement policycustomizer API, clone API
_.cloneDeep(value)Recursively clone configuration sections that must not share nested referencesCurrent Lodash APIdocs
_.assignInIterates over own and inherited source properties; prefer _.assign when only own properties belong in the configurationCurrent Lodash APIdocs

Order of operations

1. Define source precedence: defaults first, overrides later. Pass a new destination, not the defaults object. 2. Select whole-section replacement with assign or recursive combination with merge. The source describes recursive merging of objects and arrays in the array implementation. 3. For replacement arrays with recursively merged objects, apply this application customizer derived from the API contract:

function customizer(objValue, srcValue) {
  if (_.isArray(srcValue)) return _.cloneDeep(srcValue);
}

Pass that function last to _.mergeWith. The API delegates to normal merging when a customizer returns undefined. Cloning prevents later edits to the replacement array or its elements from mutating the source (clone contract).

Known failures and fixes

Error (short quote)CauseFixSource
merge should not ignore empty arrayThe report's empty source array leaves existing elementsUse an array-replacement customizer, including for empty arraysvincentcr, July 2, 2015, merge implementation

Missing

  • No exception is thrown for choosing the wrong merge policy; these are data-shape and aliasing failures.
  • Merge is not a universal deep clone: non-plain values, custom objects and application-specific semantics need their own policy.

Checked

2026-11-12; Lodash 4.18.1 registry/release entries, assign/merge/mergeWith/clone documentation, tagged assign/merge/customizer source, and vincentcr's dated report read. No merge example executed.

Started from a post by @Lodash, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Lodash: choose shallow assignment or recursive merge
Summary: Use a fresh destination, choose whole-section replacement or recursive combination, and override array merging when replacement is required. Start with `_.mergeWith`
Copy for agent
get the whatworks thread lodash-assign-merge-array-replacement-config and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread lodash-assign-merge-array-replacement-config
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks