You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the toggleAttribute(qualifiedName, force) spec, toggling an attribute should only result in a change if the attribute actually changes. In other words, if the attribute is already present and force is true or if the attribute is not present and force is false, the attribute shouldn't change.
When the polyfill is loaded, the attribute is always changed, resulting in the attributeChangedCallback firing too frequently.
This is also inconsistent with how it works out of the box in the latest versions of Chrome, Firefox and Edge.
It is especially problematic, because it breaks the spec for all web components on the page, not just components that use the scoped registry.
In our case, it lead to an unrelated piece of code behaving differently when the polyfill was loaded elsewhere.
Example
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><scriptsrc="https://unpkg.com/@webcomponents/[email protected]/src/scoped-custom-element-registry.js"></script></head><body><scripttype="text/javascript">customElements.define('my-element',classMyElementextendsHTMLElement{staticgetobservedAttributes(){return['param'];}attributeChangedCallback(name,oldValue,newValue){console.log('attributeChangedCallback',{ name, oldValue, newValue });}});constelement=document.createElement('my-element');document.body.append(element);// This should log: first setting of paramelement.setAttribute('param','');// This should log: removing the paramelement.toggleAttribute('param',false);// This shouldn't log: parameter is not presentelement.toggleAttribute('param',false);// This should log: adding the parameter element.toggleAttribute('param',true);// This shouldn't log: parameter is already presentelement.toggleAttribute('param',true);</script></body></html>
When the polyfill is not included, the attributeChangedCallback fires 3 times, resulting in 3 log statements.
When the polyfill is included, the attributeChangedCallback fires 5 times, resulting in 5 log statements.
Expected behavior
attributeChangedCallback is only called when the attribute is actually toggled
Actual behavior
attributeChangedCallback is also called when the attribute presence remains the same
Version
0.0.9
Browsers affected
Chrome
Firefox
Edge
Safari
IE 11
(These are the only browsers I can test)
The text was updated successfully, but these errors were encountered:
Description
According to the
toggleAttribute(qualifiedName, force)
spec, toggling an attribute should only result in a change if the attribute actually changes. In other words, if the attribute is already present and force istrue
or if the attribute is not present and force isfalse
, the attribute shouldn't change.When the polyfill is loaded, the attribute is always changed, resulting in the
attributeChangedCallback
firing too frequently.This is also inconsistent with how it works out of the box in the latest versions of Chrome, Firefox and Edge.
It is especially problematic, because it breaks the spec for all web components on the page, not just components that use the scoped registry.
In our case, it lead to an unrelated piece of code behaving differently when the polyfill was loaded elsewhere.
Example
attributeChangedCallback
fires 3 times, resulting in 3 log statements.attributeChangedCallback
fires 5 times, resulting in 5 log statements.Expected behavior
attributeChangedCallback
is only called when the attribute is actually toggledActual behavior
attributeChangedCallback
is also called when the attribute presence remains the sameVersion
0.0.9
Browsers affected
(These are the only browsers I can test)
The text was updated successfully, but these errors were encountered: