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 initmutative 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.
With mutable true, apply() now throws if a patch replaces the root state, which cannot be replaced in place.
Patch-value copying now preserves own symbol keys and keeps an own __proto__ key as a data property.
apply() rejects patch paths ending in __proto__ on objects or arrays, and checks coercible property keys after conversion.
For Set patch paths, apply() reads an item only at its index and throws for other keys, preventing paths through __proto__.
apply() now uses a Map key in a patch path as-is instead of converting it to a string.
Array patches now record changes between 0 and -0, and unchanged NaN elements no longer yield replace patches.
When an array is shortened and then lengthened, patches now replace the indices exposed again, so replay and inverse replay preserve the correct elements.
An explicit state type with an async recipe, including the curried form, now returns Promise<State>.
current() now snapshots assigned draftable objects together with the drafts they hold, rather than exposing later draft changes through the snapshot.
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.
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.
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.
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.
Builds now target ES2018 instead of ES2015; engines that support Proxy but not ES2018 syntax need Mutative transpiled by the build.
Map and Set draft iterators now continue from their consumed position and expose iterator helpers where the engine supports them.
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.
A Map key that is an array is now held as one patch-path segment instead of being spread into multiple segments.
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.
With a mark returning mutable, values assigned or moved by the recipe are read back as assigned, through the draft and in current().
Objects made draftable by mark now preserve an own __proto__ key as a property on their copy rather than replacing its prototype.
Changed drafts moved away from their original key no longer emit patches under the old path; their parent patches carry the value.
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.
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.
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.
Nested-draft patches now precede parent patches, matching Immer; unchanged drafts at their original index no longer emit replace patches.
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.
If a producer fails after its recipe returns, its drafts are now revoked and its array method cache released, while preserving the original error.
Production builds now throw minified errors with codes and a link instead of full messages; code matching production error messages must match codes.
With enableAutoFreeze, production builds no longer search frozen returned objects for drafts, while development builds throw if they find one.
A moved Set draft now keeps added, deleted and changed items at its new location when its former location is replaced or removed.
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.
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.
A Set receiving an unchanged draft now holds the original object rather than the draft's shallow copy.
An array draft with Symbol.isConcatSpreadable false now copies its elements instead of putting the whole array into the copy as one element.
Assigning undefined to a key removed by delete, shift, unshift, or a shrinking splice now adds the key back.
A nested unsafe() call no longer ends the access of the outer call.
Deprecations 1
create() warns once when given a draft with a recipe because it drafts a copy of the draft's current state.
Performance 1
Searching current(draft.list) can avoid drafting each element visited in a large array; change the match through the draft.
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.
shift, unshift, splice, and reverse move elements natively on a plain array's draft copy; indexOf, lastIndexOf, and includes search it natively.
With an explicit state type, a recipe that may return a Promise now gives State | Promise<State>.
current() of a changed array copies the current array, enabling searches without creating a draft for each element.
Map and Set instances are frozen too, and later producers skip them.
Development builds now report circular references only for objects that hold themselves; real-cycle errors name the path of the repeating object.
In development, when pathAsArray is false, patches whose paths would contain a non-string Map key or symbol key throw.
In Node.js, import resolves a module re-exporting the CommonJS build, so import and require share one instance and both follow NODE_ENV.
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().
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.
Production bundles omit development checks and warnings; production errors use short codes and link to the errors page.
Production builds throw Minified Mutative error codes with a link instead of full messages; code matching production error messages must match codes instead.
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.
Strict mode warns once when a recipe leaves 1,000 or more drafts unchanged.
Development builds warn once when a recipe leaves 1,000 or more drafts unchanged.
Fixes and other changes 11
Preserves draft finalization state.
Preserves producer ownership.
Deleting an index that an array does not have leaves the array draft unchanged.
Patches now reproduce array states when indices shrink and grow again, distinguish 0 from -0, and omit patches for elements that remain NaN.
current() now snapshots drafts whose state holds a plain Set with drafts, and assigned draftable objects together with the drafts they hold.
current() now returns a snapshot for a draft whose state holds a plain Set containing drafts.
A curried recipe that annotates its draft and returns a new state now returns State instead of being typed as a manual draft.
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.
Node.js 14.0 or later remains required.
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.
In strict mode, rawReturn() of a value without drafts no longer prints contradictory warnings.