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)

Most upvoted comments

I am coming from https://github.com/lytics/ember-data-model-fragments/issues/173 , which is the 1.13.13 version 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:

for (i = 0, l = nodes.length; i < l; i++) {
  nodes[i].didChange(events);
}

In my case, nodes.length is initially 3. Once the first iteration of this loop completes, nodes.length becomes 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, keyName is a computed property called object, which references a model fragment (MF.fragment). So nodes[0] is the first ChainNode for the object property. Within ChainNode.didChange(), it then calls didChange on the watched properties of object. The first property is called top, so it calls didChange for that key. Now here’s the kicker…

Within didChange for top, it gets its parent (i.e. object) via:

var obj = this._parent.value();

Prior to this call, this.parent._value is undefined. Within the call to value(), it evaluates the object computed property. The evaluation of object is what is causing the content of nodes to change. Prior to value(), nodes.length is 3. After value(), nodes.length is 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:

  1. Is it unexpected behavior for chain watchers to change due to a CP evaluation? I would assume that the observers are determined ahead of time, and a CP evaluation would not affect that. It seems that chainsDidChange is not expecting the list to change.
  2. What would cause the chain watchers to change? Anything other than explicit calls to addObserver / removeObserver outside of the Ember internals?

Thanks, hope this helps, and any help anyone else can give is greatly appreciated!