Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

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

Closed
Methuselah96 opened this issue Oct 17, 2020 · 1 comment · Fixed by #195
Labels
bug Something isn't working from-original-repo
Milestone

Comments

@Methuselah96
Copy link

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: immutable-js#1690

@Methuselah96
Copy link
Author

image

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

@Methuselah96 Methuselah96 added this to the 4.0 milestone Nov 14, 2020
@Methuselah96 Methuselah96 added bug Something isn't working and removed needs investigation labels Nov 14, 2020
jdeniau added a commit to jdeniau/immutable-js that referenced this issue Nov 20, 2020
jdeniau added a commit to jdeniau/immutable-js that referenced this issue Nov 20, 2020
jdeniau added a commit to jdeniau/immutable-js that referenced this issue Dec 3, 2020
Methuselah96 pushed a commit that referenced this issue Dec 3, 2020
…ault values (#195)

* throw Error when passing a instance of Record as a Record factory default values

Fixes #127

* allow Record as a Record defaultValues

* accept Record, throw on non-objects or collection

* typo

* throw on invalid default values instead of converting to object
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working from-original-repo
Projects
None yet
1 participant