# Behavior traces — immerjs/immer

> Canonical page: https://codevetter.com/unpack/immer/behavior-traces

# Behavior traces — immerjs/immer

Scanned commit 061c2425e1c9dff89e4e4189d42af1b7839dfe0a (2026-08-19). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Source inspection followed ordinary production, manual drafting, and patch replay end-to-end, plus startup, snapshots, collections, and array reordering. These traces describe execution order and meaningful branches rather than observed runtime results. They show where drafts are created, how outputs are finalized, and when user callbacks execute.
- Startup: src/immer.ts creates new Immer(), exposing its methods; instance defaults are autoFreeze_=true, useStrictShallowCopy_=false, and useStrictIteration_=false, while optional plugins require explicit enable calls. — [src/immer.ts#L27-L55](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/immer.ts#L27-L55) [src/immer.ts#L121-L123](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/immer.ts#L121-L123) [src/core/immerClass.ts#L47-L61](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L47-L61) [src/utils/plugins.ts#L46-L62](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/utils/plugins.ts#L46-L62)
- Recipe update: produce → isDraftable → enterScope → createProxy → createProxyProxy → recipe(proxy); nested reads draft lazily and writes call prepareCopy → markChanged → handleCrossReference. — [src/core/immerClass.ts#L104-L118](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L104-L118) [src/core/proxy.ts#L101-L104](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/proxy.ts#L101-L104) [src/core/proxy.ts#L150-L159](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/proxy.ts#L150-L159) [src/core/proxy.ts#L197-L214](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/proxy.ts#L197-L214)
- Recipe completion: successful execution leaves the scope, enables requested patch collection, then processResult → finalize → callback cleanup/patch generation → maybeFreeze → revokeScope → patchListener; a thrown recipe instead revokes in finally. — [src/core/immerClass.ts#L108-L118](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L108-L118) [src/core/finalize.ts#L49-L60](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/finalize.ts#L49-L60) [src/core/finalize.ts#L83-L104](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/finalize.ts#L83-L104) [src/core/scope.ts#L62-L79](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/scope.ts#L62-L79)
- Manual lifecycle: createDraft validates the base, snapshots it with current if already drafted, enters a scope, creates and marks a manual proxy, then leaves; finishDraft retrieves its owning scope and calls processResult. — [src/core/immerClass.ts#L152-L170](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L152-L170) [src/core/finalize.ts#L49-L60](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/finalize.ts#L49-L60)
- Patch round trip: produceWithPatches → produce with a listener → tuple capture; applyPatches scans backward for the last root replacement, skips earlier patches, then applies through the plugin directly to a draft or inside another produce. — [src/core/immerClass.ts#L137-L150](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L137-L150) [src/core/immerClass.ts#L205-L230](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L205-L230) [src/plugins/patches.ts#L328-L354](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/patches.ts#L328-L354)
- Snapshot: current rejects non-drafts, returns unchanged bases directly, temporarily marks modified drafts finalized to suppress drafting during copying, recursively snapshots children, and restores finalized_=false. — [src/core/current.ts#L15-L46](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/current.ts#L15-L46)
- Map update: createProxy selects proxyMap_ → DraftMap; get(key) lazily creates and caches a child draft, set(key,value) prepares a Map copy and records modification, and finalization callbacks replace nested draft references. — [src/core/immerClass.ts#L243-L258](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/immerClass.ts#L243-L258) [src/plugins/mapset.ts#L64-L74](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/mapset.ts#L64-L74) [src/plugins/mapset.ts#L117-L131](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/mapset.ts#L117-L131) [src/core/finalize.ts#L169-L191](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/finalize.ts#L169-L191)
- Array reordering: objectTraps.get selects createMethodInterceptor → enterOperation → handleReorderingOperation → executeArrayMethod → native copy sort/reverse → markAllIndicesReassigned; later element reads detect relocated base references, and finally clears operationMethod. — [src/core/proxy.ts#L114-L122](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/proxy.ts#L114-L122) [src/plugins/arrayMethods.ts#L299-L317](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/arrayMethods.ts#L299-L317) [src/plugins/arrayMethods.ts#L340-L355](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/arrayMethods.ts#L340-L355) [src/core/proxy.ts#L295-L311](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/core/proxy.ts#L295-L311) [src/plugins/arrayMethods.ts#L158-L167](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/arrayMethods.ts#L158-L167) [src/plugins/arrayMethods.ts#L407-L410](https://github.com/immerjs/immer/blob/061c2425e1c9dff89e4e4189d42af1b7839dfe0a/src/plugins/arrayMethods.ts#L407-L410)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
