Skip to content
Myr

fix: throw on circular references

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The most basic case; when an object references itself directly.

authored by aleclarson · committed by Alec Larson · parent 9a2e756 · Browse files · 1 file+5 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−1 removed

  • other:+5 added−1 removed

1 file+5 added−1 removed

modified:src/immer.js+5 added-1 removed
166 unmodified lines
167 }168169 const {onAssign} = this170 const finalizeProperty = (prop, value, parent) => {171 // Only `root` can be a draft in here.171 if (value === parent) {172 throw Error("Immer forbids circular references")173 }174175 // The only possible draft (in the scope of a `finalizeTree` call) is the `root` object.176 const inDraft = !!state && parent === root177178 if (isDraft(value)) {179 value =
33 unmodified lines