Skip to content

4.1.0

Latest

Choose a tag to compare

@unadlib unadlib released this 22 Oct 12:14

Coaction 4.1.0

Coaction 4.1 moves the draft engine to Mutative 2.0 and @coaction/history to Travels 3.0.1, which requires it. The public Coaction API is unchanged. What changes is the patches commits carry, how production builds report errors, and which Mutative version must be installed next to Coaction. All 18 public packages move to 4.1.0 together.

Highlights

Mutative 2.0

coaction, @coaction/logger, @coaction/mobx, @coaction/pinia, @coaction/valtio and @coaction/history now depend on mutative@^2.0.0, and @coaction/history also moves to travels@^3.0.1.

Patches follow Mutative 2

Commits carry the patches Mutative 2 produces. They reach the same places they did before: onStoreCommit listeners, store.patch middleware, @coaction/logger, getPatches() of @coaction/history, and the outbox of @coaction/sync.

  • The patches of a nested value come before those of its parents, the order Immer uses.
  • A draft that a recipe moves is carried by the patches of its parent instead of patches under the path it left.
  • A changed item of a Set that also gained or lost items is carried by the Set's remove and add patches.
  • A recipe that drafts a nested value, moves it within its array and then writes into it now commits Mutative's element patches instead of replacing the changed top-level keys.

Patches still replay to the same state, and inverse patches still undo them in order. Patches recorded by Coaction 4.0, such as those in a persisted sync outbox, still apply.

Production errors are codes

Production builds of Mutative throw Minified Mutative error #<code> with a link to the errors page instead of the full message. That also applies to patches Coaction applies: when a remote push returns a patch whose target does not exist, flush() of @coaction/sync rejects with Minified Mutative error #14 in production, and with Cannot apply patch at 'missing/value'. in development. Match error codes, not messages.

Smaller dependency tree

@coaction/mobx, @coaction/pinia and @coaction/valtio no longer install mutability, which they stopped using when patches began to apply through mutable snapshots and which declared Mutative 1 as its peer. The unused zustand-mutative dev dependency is gone, and @coaction/sync joins the suite at 4.1.0 with coaction@^4.1.0 as its peer.

Documentation

The README is refreshed as an overview and architectural guide, and the new Upgrading to Mutative 2 guide collects every change below in one place.

Breaking changes and migration

There is no Coaction API change. These are the cases that need attention:

  • Mutative 1 peers: npm stops with ERESOLVE when @coaction/history is installed next to a library that declares Mutative 1 as its peer, such as zustand-mutative@1 or travels@2. Upgrade those libraries to versions that accept Mutative 2, such as zustand-mutative@2 and travels@3, or stay on Coaction 4.0 until they do.
  • Patch arrays in tests: tests that compare patch arrays may need new expectations. Patch order and move semantics changed; replay results did not.
  • Bundles: Mutative selects its build from process.env.NODE_ENV, so define it in every bundle, including bundles for Node.js, or keep mutative external. A bundle for Node.js without it includes both CommonJS builds. In a browser without a bundler, map mutative to mutative/dist/mutative.esm.production.min.mjs instead.

The Upgrading to Mutative 2 guide covers each case, including Set patches and the sync outbox. The Migrating to Coaction 4.0 guide still applies to its own changes.

Release testing

  • Patch algebra property tests were updated for the patch shapes Mutative 2 produces.
  • @coaction/history is tested in CI against the minimum supported travels@3.0.1.
  • Fuzz checks that only produced the Mutative 1 inverse-order defect are retired.

Upgrade

npm install coaction@4.1.0

# For React applications:
npm install @coaction/react@4.1.0

All 18 public packages are 4.1.0. Upgrade every installed @coaction/* package together; every adapter and integration package declares coaction@^4.1.0 as its peer.

Full Changelog: v4.0.0...v4.1.0