mobx: Maximum Stack Size Exceeded
I made a simple application that has a store structured something like this:
{
tableData: []
,sortColumn: 0
,headerTypes: [Number, Date, String, String, String]
}
All of that is observable. I then made a computed view of the table data:
@computed get sortedData() {
return this.tableData.sort(this.getSortFn(this.sortType, this.sortColumn));
}
I then fill the tableData with ~10000 items that contains data like:
[0, new Date(), “foo”, “foo”, “foo”]
and I render it out via:
import React, { Component, PropTypes } from 'react';
import {observer} from "mobs-react";
import Row from './Flexbox/Row.jsx';
import Col from './Flexbox/Col.jsx';
import Box from './Flexbox/Box.jsx';
import DemoListItem from './DemoListItem.jsx';
import store from '../Store/DemoTableStore.jsx';
observer
class DemoTableListItemsView extends Component {
render() {
let table = [];
const { tableData } = this.props;
for(var i=0, end=tableData.length; i<end; ++i) {
table.push(<DemoListItem key={tableData[i][0]} data={tableData[i]}/>);
}
return <div>{table}</div>;
}
}
@observer
class DemoTable extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div style={{ margin: 20, backgroundColor: '#E4E4E4' }}>
<Row style={{ width: '100%', left: 16, backgroundColor: '#A4A4A4', margin: 0 }}>
<Col className="col-xs">
<Box border={0}>
<p style={{ textAlign: 'center', borderRadius: '0.2em' }}>
<span>Number</span>
</p>
</Box>
</Col>
<Col className="col-xs">
<Box>
<p style={{ textAlign: 'center', borderRadius: '0.2em' }}>
<span>Date</span>
</p>
</Box>
</Col>
<Col className="col-xs">
<Box >
<p style={{ textAlign: 'center', borderRadius: '0.2em' }}>
<span >String</span>
</p>
</Box>
</Col>
<Col className="col-xs">
<Box >
<p style={{ textAlign: 'center', borderRadius: '0.2em' }}>
<span >Info1</span>
</p>
</Box>
</Col>
<Col className="col-xs">
<Box >
<p style={{ textAlign: 'center', borderRadius: '0.2em' }}>
<span >Info2</span>
</p>
</Box>
</Col>
</Row>
{/*Recommended pattern by mobx, rendering a list with a component who's only job is to render the list*/}
<DemoTableListItemsView tableData={store.sortedData}/>
</div>
);
}
}
export default DemoTable;
Trying to change my sort column, I get this spewing out from mobx:
[Error] RangeError: Maximum call stack size exceeded.
quickDiff (bundle.js:39528)
bindDependencies (bundle.js:38499)
trackDerivedFunction (bundle.js:38485)
trackAndCompute (bundle.js:38425)
onDependenciesReady (bundle.js:38399)
notifyDependencyReady (bundle.js:38468)
(anonymous function) (bundle.js:38586:93)
forEach
propagateReadiness (bundle.js:38586)
propagateAtomReady (bundle.js:38314)
reportReady (bundle.js:38350)
reportChanged (bundle.js:38335)
set (bundle.js:39349)
(anonymous function) (bundle.js:39297)
sortColumn (bundle.js:147)
(anonymous function) (bundle.js:203)
handleMouseUp (bundle.js:15937)
(anonymous function)
dispatchEvent
invokeGuardedCallback (bundle.js:50174)
executeDispatch (bundle.js:42419)
executeDispatchesInOrder (bundle.js:42439)
executeDispatchesAndRelease (bundle.js:41890)
executeDispatchesAndReleaseTopLevel (bundle.js:41901)
forEach
forEachAccumulated (bundle.js:56402)
processEventQueue (bundle.js:42063)
runEventQueueInBatch (bundle.js:50201)
handleTopLevel (bundle.js:50212)
handleTopLevelImpl (bundle.js:50290)
perform (bundle.js:55852)
batchedUpdates (bundle.js:48863)
batchedUpdates (bundle.js:53572)
dispatchEvent (bundle.js:50367)
(anonymous function)
I understand 10000 rows is a lot, but why would it only explode on a computed sort? I can keep inserting more elements without any issues. Let me know if I need to be clearer or if more code is needed.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (9 by maintainers)
Commits related to this issue
- Don't splat large arrays. addresses #236, #237 — committed to mobxjs/mobx by mweststrate 8 years ago
- Removed eager cycle detection, didn't detect really new cases. Fixes #360, #236 — committed to mobxjs/mobx by mweststrate 8 years ago
yes circular refs can be used, but best use your class in that case, so that you can mark for example
menuItem.parentas@observable.refand avoid endless recursion of trying to convert your circular data structures to observables