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

dom-repeat - styles updated during runtime are not resetted if items are changed/deleted #5031

Closed
3 tasks done
derhuebiii opened this issue Jan 10, 2018 · 3 comments
Closed
3 tasks done

Comments

@derhuebiii
Copy link

derhuebiii commented Jan 10, 2018

Description

Live Demo

https://jsfiddle.net/hcdvqa9d/2/
=> Click "Delete Second". Name stays red for other names, even though it is only set for the item "Bob"

Steps to Reproduce

Create an element inside a dom-repeat that changes CSS via updateStyles.
When one element is deleted, the one taking its position (e.g. delete #5, #6 becoming #5) will have the CSS style from the deleted object.

Expected Results

Styles are resetted as it is not the same item anymore.

Actual Results

Styles stay the same like they were for the deleted item. Is this really desired behaviour?

Browsers Affected

  • Chrome
  • Firefox
  • [?] Edge
  • [?] Safari 9
  • [?] Safari 8
  • IE 11

Versions

  • Polymer: v1-2
  • webcomponents: v2
@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jan 15, 2018

What you're seeing is actually the desired behavior. Here's how <dom-repeat> works.

Whenever you mutate the array, <dom-repeat> rerenders and does a "full refresh"

this.__applyFullRefresh();

In this "full refresh", it, to achieve better performance, reuses the template instances that already exist and feeds them new data. In your case this causes each MyInnerElement#data property to be set to a new value. Just react to the property change by setting up an observer and it works: https://jsfiddle.net/hcdvqa9d/3/

@MajorBreakfast
Copy link
Contributor

BTW You don't need to use this.updateStyles({ color }) to set the color, you can set it via this.style.color directly. updateStyles() is only needed for setting CSS custom properties.

@TimvdLippe
Copy link
Contributor

@MajorBreakfast is absolutely correct. For performance reasons, we reuse the elements. You need to react on Data changes to update the styling, per the updated JSFiddle.

For restamping of dom-repeat elements, #1713 is filed which has a PR open at #4957. Therefore I am closing this issue as fixed/pending duplicate for the restamp property on dom-repeat.

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

No branches or pull requests

3 participants