preactjs / preact-custom-element

Wrap your component up as a custom element
MIT License
360 stars 52 forks source link

Fix: Preserve complex props across connectedCallback calls #71

Open xPapay opened 2 years ago

xPapay commented 2 years ago

This PR fixes the issue, when complex prop is lost on repeated connectedCallback call. It fixes it by saving all props into this._props.

The issue was that when complex prop was set as second or later prop (after vdom was created) we did not store it into this._props field. Then it is missing when connectedCallback is called implicitly (when element inserted into DOM), because we use there this._pros when rendering vdom; see: https://github.com/preactjs/preact-custom-element/blob/5790765ec0227ebb16add2f1469aef648e9f9f9e/src/index.js#L81

The simple props were not affected even if we set them as second or later prop because those are preserved in the attributes, and provided into vdom in connectedCallback, see: https://github.com/preactjs/preact-custom-element/blob/5790765ec0227ebb16add2f1469aef648e9f9f9e/src/index.js#L140

Fixes #69

trygveaa commented 3 months ago

Any chance to get this merged? It's very impractical to not be able to use complex properties normally.