-
Notifications
You must be signed in to change notification settings - Fork 2k
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
dom-repeat is not properly updating elements on filter/sort #1713
Comments
+1 |
I have seen the same issue while using the |
Can you describe the issue you're seeing, because I'm playing with the demo and I'm not seeing anything obvious. This could be a result of my ignorance of Pokemon, but if you could give a specific set of steps that produce a specific incorrect list, that would be helpful. |
Again I apologize for the Pokemon, it's the most easy to use free API I've come across so it's kinda my default for tinkering that requires an API. The easiest way to see this is by using the sort buttons. Load up the page and note the initial background of the 5th pokemon-card element. Click the This has caused me to think that the DOM itself is not being sorted but rather the data inside of the DOM and then the rendered elements are simply being reused to display the remaining data (similar to how core-list functioned before). Did you guys merge the functionality of |
I think you're on to something there, although I don't think the dom elements are actually re-used in this instance, it may have something to do with the way the elements are initialized. @kevinpschaaf would know for sure. In this case for example, using a computed binding in place of the
|
I was able to reproduce my issue and now I'm not sure it's directly related to this one, but here it is. |
@jshcrowthe The issue you're seeing is indeed due to The We will likely add an option for However, note that in general we consider it an anti-pattern to create elements that do one-shot state setup, such as inspecting attributes/properties at Something like... ...
<div id="wrap" class$="computeClass(pokemon, 'layout horizontal justified center')">
... properties: {
pokemon: Object,
value: null
},
computeClass: function(pokemon, staticClasses) {
var c;
if (!pokemon || !Array.isArray(pokemon.types)) {
c = 'normal-gradient';
} else {
c = pokemon.types[0].name + '-gradient';
}
return c + ' ' + staticClasses;
} |
@andrepl Looks like you had a couple of typos in your sample that I corrected here, which I think matches your intent? http://jsbin.com/cubaru/2/edit For each click to If you can reproduce another issue, it'd be great if you could open a separate issue so we can track these separately. |
Keeping this issue open to consider adding a |
@kevinpschaaf the changes you made to my example do prevent the bug from occurring, but it isn't always possible to build up the second collection BEFORE pushing the parent item as you've done. the bug is exposed when items are pushed onto the nested collection. I've re-opened a new issue as this definitely doesn't seem related: #1744. more info on that ticket. |
@kevinpschaaf I updated my internal project using computed classes and that solved one of my two issues. I seem to also be having an issue using an |
Think my issue is related. I get an "orphaned" user input after Dom-repeat sorts. Enter 111 in first input and click button. The 111 is left in the first position but the item it belongs to has been resorted |
@kevinpschaaf Don't know if we're still considering adding a This is problematic for stateful elements like inputs, as shown in @ryanwtyler's example, and the doc doesn't currently provide any insight or warnings here. (Ref. incorrect assumptions, above.) There are a couple of workarounds I can see here for @ryanwtyler's use case.
|
+ dom-repeat reuses elements for the sake of efficiency, and according to [1], it’s considered an anti-pattern to do one-shot state setup by inspecting attributes/properties in ready/attached. + Move state management to be more explicit instead of one-time setup in ready(). [1] Polymer/polymer#1713 Bug: Issue 3979 Change-Id: I5a7d2ae222223cf1ac8703cd30c66f004b606cfc
Fixes #1713 When restamp is true, template instances are never reused with different items. Instances mapping to current items are moved to their new location, new instances are created for any new items, and instances for removed items are discarded. This mode is generally more expensive than restamp: false as it results in more instances to be created and discarded during updates and disconnection/reconnection churn. By default, object identity is used for mapping instances to items. Set restampKey to provide key based identity. When restamp: true is used, restampKey can be used to provide a path into the item object that serves as a unique key for the item rather than using object identity, for purposes of mapping instances to items. Instances for items with the same key will be reused, while all others will be either restamped or discarded.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen! |
When you utilize the filter/sort attributes the repeated nodes are not updating properly. This is the same behavior that was exhibited in the Polycast on using core-list.
Rob gave a workaround for this by using
data-index="{{index}}"
. This seemed to fix the issue for his use case but when using the filter and sort attributes things get weird really quick.I threw together a quick demo of this (it utilizes
iron-image
andiron-ajax
so I opted to just give you a repo instead of a jsbin) it is here (Pardon the whimsical API). A link to the running demo: http://jshcrowthe.github.io/dom-repeat-bug/ (After the data loads note the position and color/images utilized then mess with the filters).The text was updated successfully, but these errors were encountered: