immutable-js-oss / immutable-js

Immutable persistent data collections for Javascript which increase efficiency and simplicity.
https://immutable-js-oss.github.io/immutable-js/
MIT License
37 stars 6 forks source link

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

Closed Methuselah96 closed 3 years ago

Methuselah96 commented 4 years ago

From @joepie91 on Tue, 12 Feb 2019 12:51:29 GMT

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).

Copied from original issue: https://github.com/immutable-js/immutable-js/issues/1690

Methuselah96 commented 3 years ago

image

The error message is much more friendly in 3.8.2, so I'm considering this a regression for now.