10000 Fix cloneDeep with circularly dependent Sets/Maps by ajgreenb · Pull Request #3123 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

Fix cloneDeep with circularly dependent Sets/Maps #3123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

ajgreenb
Copy link

I've submitted a patch below. Let me know how it should be improved! I couldn't find the tests (probably because of the work on v5?), but I wrote a passing test on the 4.17.4 release. I'll paste it below.

Fixes #3122

@jsf-clabot
Copy link
jsf-clabot commented Apr 24, 2017

CLA assistant c
8000
heck
All committers have signed the CLA.

@ajgreenb
Copy link
Author

I had this under the 'clone methods' module.

QUnit.test('`_.cloneDeep` should deep clone maps and sets with circular references', function(assert) {
  assert.expect(2);

  if (Set) {
    var object = { x: new Set };
    object.x.add(object);
    var clone = _.cloneDeep(object);
    assert.ok(lodashStable.isEqual(object, clone));
  } else {
    skipAssert(assert);
  }

  if (Map) {
    var object = { x: new Map };
    object.x.set('y', object);
    var clone = _.cloneDeep(object);
    assert.ok(lodashStable.isEqual(object, clone));
  } else {
    skipAssert(assert);
  }

});

@jdalton
Copy link
Member
jdalton commented Apr 24, 2017

Awesome!!!!

@phoet
Copy link
phoet commented Jun 21, 2018

i'm experiencing this issue as well with lodash 4.17.10 in our production setup:

  "name": "RangeError",
  "message": "Maximum call stack size exceeded",

unfortunately, even with sourcemaps i can't really pinpoint where this happens exactly and with what kind of data exactly. i suspect it's when cloneDeep is called with data that is fetched from a firebase database. since this is happening randomly, i don't have a good understanding of it. i guess i could try logging whatever is beeing deep-merged so that i might be able to see what's causing the issue.

@jdalton
Copy link
Member
jdalton commented Jun 21, 2018

Hi @phoet!

If you can manage a repro that would be great! This fix is in 4.17.10 so that means it could be elsewhere. We do recursively call baseClone though which means we could hit max call stacks. This is a known limitation but I also figured it would be a rare occurrence (it has been). If firebase data is JSON-like you could probably just perform JSON.stringify() and JSON.parse().

@phoet
Copy link
phoet commented Jun 21, 2018

@jdalton thanks for the hint and pointing to a workaournd. will see if i can find the data that is causing this.

@lock
Copy link
lock bot commented Jun 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

cloneDeep throws RangeError for Sets with circular references
5 participants
0