WebReflection / document-register-element

A stand-alone working lightweight version of the W3C Custom Elements specification
ISC License
1.13k stars 116 forks source link

Call attributeChangedCallback on every setAttribute #123

Closed cronon closed 6 years ago

cronon commented 7 years ago

Currently this callback is called only when the value of the attribute has changed. Spec says to call it even when the value hasn't changed. https://www.w3.org/TR/custom-elements/#concept-element-attributes-change https://bugs.chromium.org/p/chromium/issues/detail?id=676247

This also might cause issue with IE11 when attributeChangedCallback is not called when removing empty attribute

https://jsfiddle.net/cj1dhv7g/4/

Expected output (as in FF and Chrome):

changed attr1 null
changed attr1 null

Actual output in IE:

changed attr1 null
WebReflection commented 7 years ago

Spec says to call it even when the value hasn't changed.

same input, same output ... please tell me why you want this.

Indeed, if you set the same attribute node twice in Chrome, nothing happens.

This polyfill has been around for many years and I don't feel like this change woud benefit anyone, quite the opposite, it would slow down every project that trusted same attribute wouldn't trigger twice the same callback, which is a very easy and safe guards against infinite dispatched events /changes loops.

cronon commented 7 years ago
  1. This would be the same breaking change as Chrome developers made several months ago, as well as polyfill from polymer https://github.com/webcomponents/custom-elements/issues/85
  2. I don't care so much about following native browser behaviour, but want that issue with IE to be fixed :)