Skip to content

Commit

Permalink
fix: throw on circular references
Browse files Browse the repository at this point in the history
The most basic case; when an object references itself directly.
  • Loading branch information
aleclarson committed Jan 21, 2019
1 parent 9a2e756 commit 9c6603e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/immer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ export class Immer {

const {onAssign} = this
const finalizeProperty = (prop, value, parent) => {
// Only `root` can be a draft in here.
if (value === parent) {
throw Error("Immer forbids circular references")
}

// The only possible draft (in the scope of a `finalizeTree` call) is the `root` object.
const inDraft = !!state && parent === root

if (isDraft(value)) {
Expand Down

0 comments on commit 9c6603e

Please sign in to comment.