ember.js: ChainWatchers.notify errors on _notifyProperties by ED
TypeError: Cannot read property 'notify' of undefined
at Object.ChainWatchers.notify (http://crcogct.localhost:3000/dashboard/assets/vendor.js:28475:17)
at chainsDidChange (http://crcogct.localhost:3000/dashboard/assets/vendor.js:34505:9)
at Object.propertyDidChange (http://crcogct.localhost:3000/dashboard/assets/vendor.js:34415:5)
at contentPropertyDidChange (http://crcogct.localhost:3000/dashboard/assets/vendor.js:46339:32)
at Object.apply (http://crcogct.localhost:3000/dashboard/assets/vendor.js:37154:18)
at Object.sendEvent (http://crcogct.localhost:3000/dashboard/assets/vendor.js:30699:28)
at ObserverSet.flush (http://crcogct.localhost:3000/dashboard/assets/vendor.js:34022:25)
at Object.endPropertyChanges (http://crcogct.localhost:3000/dashboard/assets/vendor.js:34533:19)
at _notifyProperties (http://crcogct.localhost:3000/dashboard/assets/vendor.js:127142:25)
at InternalModel.adapterDidCommit (http://crcogct.localhost:3000/dashboard/assets/vendor.js:126466:19)
I’m using Ember 2.5.1 and Ember Data 2.5.2.
The error seems like it could be avoided on the Ember side. Not sure what would make the node undefined, but there should probably be a check, because otherwise it rejects the model.save() promise (although the save works, but any thens do not fire).
Original issue https://github.com/lytics/ember-data-model-fragments/issues/198
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (15 by maintainers)
I am coming from https://github.com/lytics/ember-data-model-fragments/issues/173 , which is the
1.13.13version of this error. I can consistently reproduce it in an app I’m building, and I have been able to set a conditional breakpoint to step through the process immediately before the error occurs. I’d be happy to do a screen share with @krisselden or anyone else who may have some input. I’m not convinced I can create a minimum test case, but this may be the next best thing.I’ll try to explain it here. The problem happens in
chainsDidChange:In my case,
nodes.lengthis initially 3. Once the first iteration of this loop completes,nodes.lengthbecomes 1. Therefore,nodes[i]is out of bounds for the second iteration. Why does that happen? Let’s dig in deeper.In the top-level call of
chainsDidChange,keyNameis a computed property calledobject, which references a model fragment (MF.fragment). Sonodes[0]is the first ChainNode for theobjectproperty. WithinChainNode.didChange(), it then callsdidChangeon the watched properties ofobject. The first property is calledtop, so it callsdidChangefor that key. Now here’s the kicker…Within
didChangefortop, it gets its parent (i.e.object) via:Prior to this call,
this.parent._valueis undefined. Within the call tovalue(), it evaluates theobjectcomputed property. The evaluation ofobjectis what is causing the content ofnodesto change. Prior tovalue(),nodes.lengthis 3. Aftervalue(),nodes.lengthis 1.Long story short: when the object notifies its properties’ observers of changes, the object is recomputed which changes the list of observers.
A few questions that may help us get to the bottom of it:
chainsDidChangeis not expecting the list to change.addObserver/removeObserveroutside of the Ember internals?Thanks, hope this helps, and any help anyone else can give is greatly appreciated!