Open dritter opened 1 year ago
The problem is that Svelte during hydration expects the DOM to look the same as when it was server-rendered. But the custom element already scaffolded itself, so Svelte trashes it. That makes sense for normal elements because it aligns Svelte and the DOM, but in case of custom elements ... tricky.
Another workaround is to defer registration of the custom element a bit until Svelte has finished hydrating.
Thanks for looking into this @dummdidumm
Defering the registration of the custom element is unfortunately not an option, because of two reasons:
if (isFrameworkA()) { ... } elseif (isFrameworkB()) { ... }
code.setTimeout()
Version, but that would be a guessed value, that differs from device to device. It may be deferrable when using the custom element in an onMount()
hook, but that would lead to my initial workaround ({@html ...}
).
Describe the bug
At work we use a couple of webcomponents (custom elements) from different teams. We chose webcomponents to be framework agnostic so they work everywhere. If these webcomponents render markup that markup gets removed on the client side when svelte takes over control. This does even happen, if I mark this component as custom element in vite (= has no effect, thus not included in reproducer):
Pointers in reproducer
The custom element gets defined in app.html and is used in +page.svelte.
Workaround
It works, if I wrap the component in
@html
(I guess that disables the hydration):Maybe that could be done automatically if svelte detects a custom element?
Other tries
I tested this even with https://github.com/sveltejs/svelte/pull/8457 and it still happens. It would be nice, if this case could be considered in this PR.
Reproduction
Bildschirmaufzeichnung vom 2023-04-19, 09-54-12.webm
Logs
No response
System Info
Severity
annoyance
Additional Information
No response