preactjs / preact-custom-element

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

fix: getting vdom prop when vdom is not ready yet #66

Open finalclass opened 2 years ago

finalclass commented 2 years ago

In my app something weird started to happen. I got this error message:

index.js:613 Uncaught TypeError: Cannot read property 'props' of undefined
    at HTMLElement.get (index.js:27)
(redacted)

This have been happening to me when I was using my web component like that:

<sw-text-input value="some value"/>

The weird thing is that removing the value attribute fixes it. Also any other attribute works just fine and also using this component in some other place of the app also works fine (even with the value attribute set).

For some unknown reason preact (or something else?) is trying to read the property of a component before the vdom is there, that's why we need to check for vdom existance (just like it's done in the set function).

lfleischmann commented 2 years ago

Hi there,

it looks like this might be related to https://github.com/preactjs/preact-custom-element/issues/73? A local test using the change proposed in this PR indicated that the Svelte issue would be solved by this. Any possibility that this gets merged? Or does the change have any other unwanted consequences?

@marvinhagemeister

jvanderberg commented 4 months ago

Any chance this can get merged? Just here to vote for it, as it makes Svelte interop difficult, it also just feels a bit untidy - getters shouldn't throw.