Skip to content
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

"too much recursion" error when creating a Record type from an instance of another Record #1690

Closed
joepie91 opened this issue Feb 12, 2019 · 3 comments · Fixed by #1833
Closed
Labels
Milestone

Comments

@joepie91
Copy link

What happened

When creating a new Record type, and passing in an instance of another Record as the schema / default values, Immutable will end up in an infinite recursion loop, yielding the following error:

selection_919

I don't know whether it conceptually makes sense to try to do this (see the repro below); in my case the 'nested Record' structure was caused by a mistake during refactoring.

However, the current error is completely unclear about the cause of the issue, and provides no real way to track down the cause. I ended up spending several hours trying to find the root cause.

Expected behaviour: Either produce an understandable error with concrete guidance (if this is not supposed to be supported), or work correctly without breaking (if it is supposed to be supported).

How to reproduce

Repro:

const immutable = require("immutable");

let Foo = immutable.Record({foo: "bar"});
let fooInstance = Foo();
let Bar = immutable.Record(fooInstance);
let barInstance = Bar();

Tested in Firefox 64.0 with latest Immutable.js (4.0.0-rc.12).

@ttamminen
Copy link

I think I know what you tried to achieve. Maybe there should be an error or something, but I think this is more clear.

const immutable = require("immutable");

let fooSchema = {foo: "bar"};
let Foo = immutable.Record(fooSchema);
let fooInstance = Foo({ foo: "myFoo" });
let Bar = immutable.Record(fooSchema);
let barInstance = Bar({ foo: 'barFoo' });

Or, if you really want the Bar default value to be what fooInstance has.

let Foo = immutable.Record({foo: "bar"});
let fooInstance = Foo();
let Bar = immutable.Record(fooInstance.toJS());
let barInstance = Bar();

Which in this case would be a value "bar" for foo property.

@joepie91
Copy link
Author

joepie91 commented Mar 13, 2019

Nah, I didn't actually intend to have two separate Record types and have one contain the other; I just erroneously tried to wrap an object in immutable.Record(...) twice in a piece of refactored code (where it should've only been wrapped once).

The problem is that it didn't produce an understandable error, and therefore it took a long time to figure out that the problem was an erroneous double call of immutable.Record.

@jdeniau
Copy link
Member

jdeniau commented Jun 29, 2021

Thank you for your bug report. The immutable-js oss fork will soon be merged and a fix for this issue has been included in #1833. Once this PR is merged, this issue will be resolved in the main branch. We will then do our best to to release the 4.0.0 version.

Commit reference: 9c7e5cb

@jdeniau jdeniau linked a pull request Jun 29, 2021 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants