Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
trevordixon opened this issue Jul 1, 2015 · 7 comments
Assignees
Labels

Comments

@trevordixon
Copy link
Contributor

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".

@masonlouchart
Copy link

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
Copy link
Contributor Author

@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.

@masonlouchart
Copy link

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

@trevordixon
Copy link
Contributor Author

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 Jul 7, 2015
@kevinpschaaf kevinpschaaf self-assigned this Jul 7, 2015
@kevinpschaaf
Copy link
Member

Confirmed the issue, fix is in progress.

@kevinpschaaf kevinpschaaf added p0 and removed p1 labels Jul 15, 2015
sorvell pushed a commit that referenced this issue Jul 16, 2015
Fix reuse logic to handle multiple mutations in same turn. Fixes #2009.
@kevinpschaaf
Copy link
Member

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...

@sansantosh
Copy link

If I store 'this' in self variable and after REST operation success if I do self.shift('arrayName') or self.shift('arrayName', 1, 1). This operation fails. It adds weird item in array which results in this error: polymer.html:4209 [dom-repeat::dom-repeat]: expected array for items, found 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants