Skip to content

Use hasChanged to check if changing attribute is dirty #699

@cdata

Description

@cdata

We have a property that affects complex underlying state in our component. The underlying state that is affected by this property changes very rapidly (on rAF timing), and it is not worth the cost to serialize and reflect that underlying state back to the property/attribute on every frame.

So, we have configured the property with hasChanged: () => true, so that we can handle assignments to it even when the value essentially looks the same from the outside.

We received a bug report that this works as expected for property assignment, but not for setting attributes (google/model-viewer#592).

The root of the problem is that the attributeChangedCallback implementation of UpdatingElement uses a very basic, blanket dirty check that is not aware of hasChanged:

https://github.com/Polymer/lit-element/blob/508af0ee635549d1f2a87feccff4eb97b82c51ba/src/lib/updating-element.ts#L517-L521

It violates my expectations to have two different modes for dirty checking, despite explicitly configuring a check. Please consider using hasChanged in this case, or implementing an equivalent that works for attributes!

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions