CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 195
Using Map method with React causes infinite recursion #73
Description
I am not 100% sure what's happening as my research was limited. Still I'll try to explain the problem.
var constants = immutable({
BASE_PATH: '/my/files'
}),
BASE = constants.BASE_PATH,
menu = [
{
link: BASE,
title: 'Files'
},
{
link: `${BASE}/:sharing`,
title: 'Sharing'
}
];
...
render() {
var moreParams = ( this.props.params.splat || '' ).split('/'),
command = moreParams.length && moreParams[0].charAt(0) == ':' ? moreParams[0].substr(1) : null;
return (
<div className="_personal-storage">
<Menu items={ menu } />
<Storage base={ BASE } callback={ processCommand }>
<h1>Personal storage</h1>
</Storage>
</div>
);
}
Everything works this way, but as soon as I make menu
immutable, it goes to the weirdest infinite recursion in seamless-immutable.js:
Uncaught RangeError: Maximum call stack size exceeded
defineProperty @ (program):779
addPropertyTo @ seamless-immutable.js:5
makeImmutableObject @ seamless-immutable.js:342
Immutable @ seamless-immutable.js:371
Immutable @ seamless-immutable.js:367
Immutable @ seamless-immutable.js:367
Immutable @ seamless-immutable.js:367
makeImmutableArray @ seamless-immutable.js:106
Immutable @ seamless-immutable.js:354
Immutable @ seamless-immutable.js:367
The weirdest part is - it happens only if I pass menu
as a property to a react component. If I just log it to the console it works just fine. It doesn't matter if I make it immutable on declaration or later - it works the same.
When I've been debugging it, I couldn't believe my eyes - after making immutable my objects, it started making immutable React stuff {$$typeof: Symbol(react.element), key: null, ref: null, props: Object, _owner: ReactCompositeComponentWrapper…}$$typeof: Symbol(react.element)_owner: ReactCompositeComponentWrapper_self: null_source: null_store: Objectkey: nullprops: Objectref: nulltype: _default(props)__proto__: Object
and this is where the infinite recursion happens. But why does it make it immutable at all? I have no idea.