unstale

npm / mutative

mutative

What changed in mutative 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.

37 breaking1 deprecations1 performance15 behavior and defaults11 fixes and other

See which of these apply to your code, ranked, in your agent:

npx @unstale/cli init

@unstale/cli on npm

mutative 265 changes

Breaking changes 37

  • apply() rejects paths ending in __proto__, reads Set items only at their indices, and copies symbol and own __proto__ keys of patch values.

    2.0.0release notes

  • With mutable true, apply() now throws if a patch replaces the root state, which cannot be replaced in place.

    2.0.0upgrade guide

  • Patch-value copying now preserves own symbol keys and keeps an own __proto__ key as a data property.

    2.0.0upgrade guide

  • apply() rejects patch paths ending in __proto__ on objects or arrays, and checks coercible property keys after conversion.

    2.0.0upgrade guide

  • For Set patch paths, apply() reads an item only at its index and throws for other keys, preventing paths through __proto__.

    2.0.0upgrade guide

  • apply() now uses a Map key in a patch path as-is instead of converting it to a string.

    2.0.0upgrade guide

  • Array patches now record changes between 0 and -0, and unchanged NaN elements no longer yield replace patches.

    2.0.0upgrade guide

  • When an array is shortened and then lengthened, patches now replace the indices exposed again, so replay and inverse replay preserve the correct elements.

    2.0.0upgrade guide

  • An explicit state type with an async recipe, including the curried form, now returns Promise<State>.

    2.0.0release notesupgrade guide

  • current() now snapshots assigned draftable objects together with the drafts they hold, rather than exposing later draft changes through the snapshot.

    2.0.0upgrade guide

  • A curried producer with an annotated draft that returns a new state now has a State return type, or Promise<State> for an async recipe.

    2.0.0upgrade guide

  • This ESM file reads process.env.NODE_ENV when loaded and throws process is not defined in runtimes without process; use the production ESM file or UMD build there.

    2.0.0release notesupgrade guide

  • Map and Set instances are now frozen too; later producers skip frozen Map or Set entries, and self-containing collections no longer overflow the stack in production.

    2.0.0upgrade guide

  • With pathAsArray false, development builds throw if a patch path would stringify a non-string Map key or symbol key; use default array paths for such keys.

    2.0.0upgrade guide

  • Builds now target ES2018 instead of ES2015; engines that support Proxy but not ES2018 syntax need Mutative transpiled by the build.

    2.0.0release notesupgrade guide

  • Map and Set draft iterators now continue from their consumed position and expose iterator helpers where the engine supports them.

    2.0.0upgrade guide

  • Map value and entry iterators and all Set iterators can no longer yield after the producer finishes or fails, or after a manual draft is finalized; they throw TypeError.

    2.0.0upgrade guide

  • A Map key that is an array is now held as one patch-path segment instead of being spread into multiple segments.

    2.0.0upgrade guide

  • Passing a draft to the set() method of a Map draft now throws because the next state would keep the revoked draft as a key.

    2.0.0release notesupgrade guide

  • With a mark returning mutable, values assigned or moved by the recipe are read back as assigned, through the draft and in current().

    2.0.0upgrade guide

  • Objects made draftable by mark now preserve an own __proto__ key as a property on their copy rather than replacing its prototype.

    2.0.0upgrade guide

  • Changed drafts moved away from their original key no longer emit patches under the old path; their parent patches carry the value.

    2.0.0upgrade guide

  • Assigning to a key held as an own data property now sets that property as in JavaScript, even if a prototype defines a setter of the same name.

    2.0.0release notesupgrade guide

  • A patch value that was a draft is now the object held by the next state rather than a deep copy, and is frozen with the state when auto-freezing is enabled.

    2.0.0upgrade guide

  • Nested draft patches now precede parent patches; moved drafts emit no patches under their old paths, and patch values that were drafts are the objects held by the next state.

    2.0.0release notes

  • Nested-draft patches now precede parent patches, matching Immer; unchanged drafts at their original index no longer emit replace patches.

    2.0.0upgrade guide

  • The ESM entry checks NODE_ENV at each development check; production bundles that define it as production drop development checks and warnings and throw minified errors.

    2.0.0upgrade guide

  • If a producer fails after its recipe returns, its drafts are now revoked and its array method cache released, while preserving the original error.

    2.0.0upgrade guide

  • Production builds now throw minified errors with codes and a link instead of full messages; code matching production error messages must match codes.

    2.0.0upgrade guide

  • With enableAutoFreeze, production builds no longer search frozen returned objects for drafts, while development builds throw if they find one.

    2.0.0release notesupgrade guide

  • A moved Set draft now keeps added, deleted and changed items at its new location when its former location is replaced or removed.

    2.0.0upgrade guide

  • Changed Set items combined with additions or removals are carried by the Set's remove and add patches, rather than patches tied to item positions.

    2.0.0upgrade guide

  • A Set subclass draft now changes a copy that is an instance of the subclass, so its own add, has, delete and clear methods take effect during the recipe.

    2.0.0upgrade guide

  • A Set receiving an unchanged draft now holds the original object rather than the draft's shallow copy.

    2.0.0upgrade guide

  • An array draft with Symbol.isConcatSpreadable false now copies its elements instead of putting the whole array into the copy as one element.

    2.0.0upgrade guide

  • Assigning undefined to a key removed by delete, shift, unshift, or a shrinking splice now adds the key back.

    2.0.0release notesupgrade guide

  • A nested unsafe() call no longer ends the access of the outer call.

    2.0.0release notesupgrade guide

Deprecations 1

  • create() warns once when given a draft with a recipe because it drafts a copy of the draft's current state.

    2.0.0release notesupgrade guide

Performance 1

  • Searching current(draft.list) can avoid drafting each element visited in a large array; change the match through the draft.

    2.0.0upgrade guide

Behavior and default changes 15

  • apply() types frozen and in-place results: enableAutoFreeze: true returns Immutable<State>, while mutable typed as boolean returns State | void.

    2.0.0release notesupgrade guide

  • shift, unshift, splice, and reverse move elements natively on a plain array's draft copy; indexOf, lastIndexOf, and includes search it natively.

    2.0.0release notesupgrade guide

  • With an explicit state type, a recipe that may return a Promise now gives State | Promise<State>.

    2.0.0release notesupgrade guide

  • current() of a changed array copies the current array, enabling searches without creating a draft for each element.

    2.0.0release notesupgrade guide

  • Map and Set instances are frozen too, and later producers skip them.

    2.0.0release notes

  • Development builds now report circular references only for objects that hold themselves; real-cycle errors name the path of the repeating object.

    2.0.0upgrade guide

  • In development, when pathAsArray is false, patches whose paths would contain a non-string Map key or symbol key throw.

    2.0.0release notes

  • In Node.js, import resolves a module re-exporting the CommonJS build, so import and require share one instance and both follow NODE_ENV.

    2.0.0release notesupgrade guide

  • Map drafts freeze and iterate like built-in Maps; patches preserve array keys as one path segment, and Map keys are used as they are by apply().

    2.0.0release notes

  • The ESM entry checks process.env.NODE_ENV at each development check; Node-targeted bundles that do not define it may include both CommonJS builds.

    2.0.0release notes

  • Production bundles omit development checks and warnings; production errors use short codes and link to the errors page.

    2.0.0release notes

  • Production builds throw Minified Mutative error codes with a link instead of full messages; code matching production error messages must match codes instead.

    2.0.0release notes

  • Set changes and patches now preserve changed items, moved Set drafts, and unchanged-draft assignment behavior; Set drafts freeze and iterate like built-in Sets.

    2.0.0release notes

  • Strict mode warns once when a recipe leaves 1,000 or more drafts unchanged.

    2.0.0release notes

  • Development builds warn once when a recipe leaves 1,000 or more drafts unchanged.

    2.0.0upgrade guide

Fixes and other changes 11

  • Preserves draft finalization state.

    2.0.2release notes

  • Preserves producer ownership.

    2.0.2release notes

  • Deleting an index that an array does not have leaves the array draft unchanged.

    2.0.1release notes

  • Patches now reproduce array states when indices shrink and grow again, distinguish 0 from -0, and omit patches for elements that remain NaN.

    2.0.0release notes

  • current() now snapshots drafts whose state holds a plain Set with drafts, and assigned draftable objects together with the drafts they hold.

    2.0.0release notes

  • current() now returns a snapshot for a draft whose state holds a plain Set containing drafts.

    2.0.0upgrade guide

  • A curried recipe that annotates its draft and returns a new state now returns State instead of being typed as a manual draft.

    2.0.0release notes

  • Every changed item of a Set now keeps its changes when patches are enabled; previously, nested changes to multiple non-root Set items could lose all but one.

    2.0.0upgrade guide

  • Node.js 14.0 or later remains required.

    2.0.0release notes

  • Assigning a draft's original object to its key is recorded according to whether the draft was read there or moved there, fixing missing or spurious patches.

    2.0.0upgrade guide

  • In strict mode, rawReturn() of a value without drafts no longer prints contradictory warnings.

    2.0.0upgrade guide