archetype icon indicating copy to clipboard operation
archetype copied to clipboard

lodash cloneDeep and cyclic data leads to "call stack size exceeded"

Open mfeblowitz opened this issue 3 years ago • 0 comments

[email protected], using [email protected], 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:

  1. replace lodash.cloneDeep with clone, in each file:

    • replace const cloneDeep = require('lodash.clonedeep'); with const clone = require('clone');
    • replace references to _.cloneDeep(...) with clone(...)
  2. replace 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.

mfeblowitz avatar Oct 11 '22 15:10 mfeblowitz