lodash cloneDeep and cyclic data leads to "call stack size exceeded" #26
Description
archetype@0.13.0, using lodash.clonedeep@4.5.0, results in "call stack size exceeded", presumably due to cyclic data in:
- archetype/src/type.js -
Type
constructor method - archetype/src/index.js -
Archetype
constructor and visitObject methods
So, first questions: which uses of archetype are circular (and how detected), and can the circularities be avoided or addressed?
As for possible workarounds/solutions, which of the many deepClone alternatives would be appropriate?
One possible solution - rfdc - addresses circular structures, but at a %25 performance:
const clone = require('rfdc')(circles: true)
...
b = clone(a)
The key question its whether circularities can be eliminated, whether an across-the-board %25 performance reduction can be tolerated, or whether circularity can be detected, to determine which flavor of deep cloning should be applied.
Some (problematic) workarounds:
-
replace lodash.cloneDeep with clone, in each file:
- replace
const cloneDeep = require('lodash.clonedeep');
withconst clone = require('clone');
- replace references to
_.cloneDeep(...)
with clone(...)
- replace
The problem with each is that circular values are replaced with a string: '[Circular]', presumably problematic when dealing with types.
Ultimately, this needs to be fixed in archetype, as that's where reliance on lodash.deepClone breaks down.