Padax / w-components

JavaScript library based on Web Components.
MIT License
22 stars 2 forks source link

First-added attribute on initial render shouldn't trigger update #109

Closed nizniz187 closed 2 years ago

nizniz187 commented 3 years ago

Followed by commit #103 & MR #104.

nizniz187 commented 3 years ago

The solutions we've tried:

  1. Delay the timing of binding attributeChangedCallback: failed. The attributeChanged will still be triggered on the initial rendering.
  2. Assign initial value for all defined attributes before the init function triggered: failed. Would bumped into the error 'Uncaught DOMException: Failed to construct 'CustomElement': The result must not have attributes'. The initial attribute assignment is actually limited from the spec. So at this point I would make a conclusion that this issue is unable to fix.

The best thing we can do may be putting a notice in our documentation:

The update function will be triggered on initial rendering if any attribute is assigned.

nizniz187 commented 2 years ago

After a second thought, we could actually utilize the connectedCallback to identify whether the component is initialized. Because the order of triggering would be: constructor -> attributeChangedCallback -> connectedCallback.

cwpeng commented 2 years ago

I have tried connectedCallback last week, but failed. Maybe we can try again.