I'm right now trying to integrate a Custom Element that has been created via preact-custom-element into a Svelte application.
Whenever the CE is rendered by svelte an error comes up that emerges at the "place" where Svelte hands over properties/attributes to the Custom Element:
("Uncaught TypeError: Cannot read properties of undefined (reading 'props')")
The place this error is thrown is this line of code:
The function that is responsible always reads (get) the value from the custom element (via the typeof statement) before it sets the value, while preact-custom-element assumes that the value is set before it is read.
Please let me know if my analysis makes sense and if you'd consider this something that should be fixed here or rather in the svelte implementation!
I'm right now trying to integrate a Custom Element that has been created via preact-custom-element into a Svelte application. Whenever the CE is rendered by svelte an error comes up that emerges at the "place" where Svelte hands over properties/attributes to the Custom Element:
The place this error is thrown is this line of code:![image](https://user-images.githubusercontent.com/1330022/188902458-e9b10ef3-892a-4398-b8af-d86b460bac6b.png)
(https://github.com/preactjs/preact-custom-element/blob/master/src/index.js#L27)
My understanding is that preact-custom-element assumes that a property value will always be set before it is ever read. Therefore the if statement in line 30 that checks for an initialized vdom (https://github.com/preactjs/preact-custom-element/blob/master/src/index.js#L30).
Now the problem gets clearer when we look at the code where svelte assigns values to the custom element:
(https://github.com/sveltejs/svelte/blob/master/src/runtime/internal/dom.ts#L315)
The function that is responsible always reads (
get
) the value from the custom element (via thetypeof
statement) before it sets the value, while preact-custom-element assumes that the value is set before it is read.Please let me know if my analysis makes sense and if you'd consider this something that should be fixed here or rather in the svelte implementation!