emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.47k stars 4.21k forks source link

array_proxy.js: cannot read property 'length' of undefined #17441

Closed srsgores closed 4 years ago

srsgores commented 5 years ago

Upon upgrading a legacy ember app, the model is unable to resolve to ArrayProxy:

array_proxy.js:155 Uncaught TypeError: Cannot set property 'length' of undefined at Class.objectAt (array_proxy.js:155) at objectAt (metal.js:1300) at EmberArrayIterator.valueFor (glimmer.js:2333) at EmberArrayIterator.next (glimmer.js:2290) at ReferenceIterator.next (reference.js:373) at Object.APPEND_OPCODES.add [as evaluate] (runtime.js:1288) at AppendOpcodes.evaluate (runtime.js:39) at LowLevelVM.evaluateSyscall (runtime.js:2179) at LowLevelVM.evaluateInner (runtime.js:2153) at LowLevelVM.evaluateOuter (runtime.js:2146)

The error occurs on this line:

let length = this._objects.length = (0, _metal.get)(arrangedContent, 'length');

As here.

By the looks of it, some models will not have prepopulated with this.objects, so we should check that this array is also undefined as opposed to just null:

if (this._objects === null || this._objects === undefined) {
    this._objects = [];
}
rwjblue commented 5 years ago

Can you provide a demo / reproduction?

srsgores commented 5 years ago

@rwjblue: I can PM you a link. Leave your contact details

srsgores commented 5 years ago

Which e-mail am I sending the repro to?

pixelhandler commented 5 years ago

@srsgores Often we use https://ember-twiddle.com/ or if that doesn't work for your use case a sample repository and link to it here. The goal with a reproduction of the issue is to demonstrate the bug, and in many cases when trying to create a simple example we find out where the bug is, either in our codebase or in some cases in the framework.

Also, sharing a simple reproduction in code helps others address a problematic use case. Can you re-create the issue using ember-twiddle?

locks commented 4 years ago

Closing due to lack of reproduction. If you are able to publish the reproduction, or if you encounter the same bug for newer versions of Ember, please let us know!