Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Deeply nested object was detected

Alexey Shamrin edited this page Apr 14, 2016 · 4 revisions

Have you got the following error?

Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)?

It usually happens when seamless-immutable tries to wrap an object with circular references, like React element. For example:

Immutable([1,2,3]).map(function() { return <div /> })

We catch this problem to prevent JavaScript engine from slowing down browser tab and ultimately failing with stack overflow. We do it only during development. Production build doesn't have this protection.

How to fix the problem?

  1. Replace builtin map method with lodash/underscore map: _.map(Immutable([1,2,3]), function() { return <div /> })
  2. Call asMutable before calling map: Immutable([1,2,3]).asMutable().map(function() { return <div /> }).
  3. Wait for PR #120 to get merged. It will skip making React elements immutable. (This won't help if the circular reference was not in React element.)

How to prevent deep (but not circular) object from failing?

Increase maximum stack depth by passing it as a third argument to Immutable. For example: Immutable(deepObject, null, 256). Default maximum stack depth is 64.

Links

Issue #73, issue #16, PR #119, PR #120

Clone this wiki locally