(Posted as an archetype issue)
[email protected], using [email protected], sometimes results in "call stack size exceeded", presumably due to circular references in the data, specifically encountered in:
- archetype/src/type.js -
Typeconstructor method - archetype/src/index.js -
Archetypeconstructor 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, albeit at a %25 performance hit:
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 references to clone(...)
- replace lodash.cloneDeep with fclone, as discussed here.
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.