Skip to content

Loading…

JS error with dom-repeat and async splice array element in followed by remove last element #2009

Closed
trevordixon opened this Issue · 6 comments

3 participants

@trevordixon

Demonstration: http://plnkr.co/edit/isFkxmfNUa5mrhZL1wST?p=preview

If you splice an element into an array then remove the last element (in that order), in an async handler, and the array is items for a dom-repeat, you'll trigger a javascript error "Cannot read property '_children' of undefined".

@LM450N

The splice method belongs to the Array.prototype. So, it must be called directly on the array. Moreover, you have to reflect the property as attribute. Else the DOM is not updated on array value change.

Please see this version of your Plunkr

@trevordixon

@LM450N Polymer 1.0 requires this.splice('arr', ...) instead of this.arr.splice(...). See https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-repeat.

@LM450N

Yes you're right. I learned this yesterday. My apologies.

@trevordixon

If you remove the last element first, then insert an element, there's no error, but once all elements are the same, dom-repeat does strange things.

http://jsbin.com/quyubahohu/edit?html,console,output

@kevinpschaaf kevinpschaaf added the p1 label
@kevinpschaaf kevinpschaaf self-assigned this
@kevinpschaaf

Confirmed the issue, fix is in progress.

@kevinpschaaf kevinpschaaf added p0 and removed p1 labels
@kevinpschaaf

The primary issue related to errors (throwing) when mutating an array multiple times in the same turn is resolved.

@trevordixon Note that your repro case also exhibited the issue in #1913 since you were pushing duplicate values ('foo') on to the array, which accounts for the "strange things".

Original repro on master:
http://jsbin.com/tekiwu/edit?html,console,output

Confirmed that replacing 'foo' with Math.random() makes it work as expected:
http://jsbin.com/zubama/edit?html,console,output

Stay tuned on #1913 if the duplicates issue was important to your use case...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.