mobx-state-tree: Error: [mobx-state-tree] setParent is not supposed to be called on scalar nodes
[EDITED] Change “self.items.unshift(id)” by “self.items = [id, …self.items.slice()]” fixed issue [/EDITED]
I have:
- I think something is not working as it should.
- I’ve checked documentation and searched for existing issues
Error below only happen with mobx-state-tree 3.0. I basically put a model into a array [ self.items.unshift(model) ] This model has another model that call getParent.
works perfectly with mobx 2.2
Error: [mobx-state-tree] setParent is not supposed to be called on scalar nodes
at fail (mobx-state-tree.module.js:2286)
at ScalarNode$$1.setParent (mobx-state-tree.module.js:885)
at ArrayType$$1.willChange (mobx-state-tree.module.js:2979)
at interceptChange$$1 (mobx.module.js:2688)
at ObservableArrayAdministration.spliceWithArray (mobx.module.js:2856)
at Proxy.unshift (mobx.module.js:3012)
at unshift (page.js:126)
at executeAction$$1 (mobx.module.js:613)
at res (mobx.module.js:605)
at runMiddleWares (mobx-state-tree.module.js:1907)
code example. I have many pages, that only keep ids, and I have a central repository to find itens with that id. I think that issue is with “get list()”
t.model('activityPage', {
items: t.optional(t.array(t.number), [])
})
.views(self => {
get list() { return self.items.map(id => getRoot(self).getItem('activity', id)) }
})
.actions(self => {
unshift(id) {
self.items.unshift(id)
}
})
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 15 (9 by maintainers)
Commits related to this issue
- (fix/deps): update MST to resolve occasional favorites bugs - splice was sometimes causing an error - c.f. https://github.com/mobxjs/mobx-state-tree/issues/928 - update MobX as well due to peerDep... — committed to agilgur5/react-native-manga-reader-app by agilgur5 5 years ago
- (fix/deps): update MST to resolve occasional favorites bugs - splice was sometimes causing an error - c.f. https://github.com/mobxjs/mobx-state-tree/issues/928 - update MobX as well due to peerDep... — committed to agilgur5/react-native-manga-reader-app by agilgur5 5 years ago
Released 3.2.2, please check if this solves the issue
To reproduce codesandbox