Repository navigation
JavaScript: upgrade mutative to 2.0.2 - #10173
Merged
Merged
Conversation
Mutative 2 warns when create() is given a draft. Four helpers did that from inside recipes, so they now change the draft in place or are handed the original value instead.
Member
Author
|
@knutwannheden based on our earlier discussion figured bump |
knutwannheden
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mutative 2.0 keeps the 1.x API. Its release notes report it as faster than 1.3.0 (4.3x on the geometric mean of its own benchmarks) and fix several cases where 1.x produced wrong states. 1.3.0 is the last 1.x release, and fixes are not being backported. The floor is
^2.0.2because 2.0.2 (unadlib/mutative#218) fixes a bug that 1.3.0 also has: an innercreate()that assigns a draft from an outercreate()could finalize it early, so later outer reads could mutate the base state. We nestproducecalls throughout the parser and formatter. I found no place where we actually hit this, so it reduces risk rather than fixes a known bug.The only change that showed up in our code is a new development-build warning when
create()is given a draft. In 1.x the draft was already handled the same way, silently. Four helpers did this from inside recipes:maybeAddOptionalMarkerin the parser now adds the marker to the draft directly.BlankLinesVisitornow uses a newupdateLastWhitespace, the in-place counterpart ofreplaceLastWhitespace.replaceLastWhitespacestill copies, so callers outside this repository see no change.WrappingAndBracesVisitornow passes the originalSpacetowithNewlineSpaceinstead of the draft.Since the Node package is consumed as CommonJS, the ESM, bundler and
NODE_ENVchanges in 2.0 don't apply. Its CommonJS entry is identical to 1.3.0's. We also don't use patches,apply(), auto-freeze,mark, strict mode or Map/Set drafts, which is where most of the migration guide's breaking changes are. Test timings didn't change, because our recipes assign fields andpushonto arrays rather than using the array and Set operations that 2.0 speeds up.Verification:
npm run typecheck,npm run buildandnpx vitest runpass: 3730 passed, 0 failed. I ran the suite once with mutative's warn-once guard patched out, to find every call site rather than just the first, and the fixed run prints none of 2.0's warnings.create()and are called with a draft finds all four helpers onmain(11 call sites) and none on this branch. A second scan found no inner recipe that stores an outer recipe's draft.recipes-angularandrecipes-reactdeclare their ownmutative ^1.x, so after this change they load 1.3.0 next to our 2.0.2. Both copies mark drafts with the sameSymbol.forkey, and nesting either version'screate()inside the other's, pluscurrent()andoriginal()across versions, gave correct results. I ran both packages' test suites from fresh clones against this branch packed as a tarball, and against the same commit built with mutative 1.3.0. The results were identical: angular 1511 passed, react 2917 passed. The same tests failed on both versions: 31 in angular'sjava-rpctests (no Java classpath locally) and 24 in react.