You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was able to get custom elements for our video player library (https://github.com/vidstack/player) to render server-side, but noticed strange behaviour when elements are hydrated. You can observe in the repro link provided.
Essentially the element is parsed and rendered by the browser when the initial HTML is served, however, after the element is claimed by Svelte whilst hydrating, it wipes the entire state out and sets all attributes/properties to null that were not set by the user (traced to this line).
This means all default prop values are set to an unexpected null value, and the style property is also reset which means all CSS variables that are set on the custom element itself are removed.
This behaviour is inconsistent between client-side and server-side rendering with Svelte. I'd expect the custom element to work mostly the same way regardless of how it's rendered.
I'm not entirely sure why the claiming process removes all attributes in the way it does so I can't suggest a solution. Maybe if it's a custom element leaving the attributes as-is?
NOTE: To clarify this only occurs with SSR (not an SPA), and only if the elements are registered before they're claimed by Svelte. As mentioned, it's because (1) the browser parses the HTML delivered from the server, (2) the element is registered, (3) the element is "upgraded" to a custom element, and then (4) Svelte in the claiming process wipes all attrs/props by resetting them to null.
Describe the bug
I was able to get custom elements for our video player library (https://github.com/vidstack/player) to render server-side, but noticed strange behaviour when elements are hydrated. You can observe in the repro link provided.
Essentially the element is parsed and rendered by the browser when the initial HTML is served, however, after the element is claimed by Svelte whilst hydrating, it wipes the entire state out and sets all attributes/properties to
null
that were not set by the user (traced to this line).This means all default prop values are set to an unexpected
null
value, and thestyle
property is also reset which means all CSS variables that are set on the custom element itself are removed.This behaviour is inconsistent between client-side and server-side rendering with Svelte. I'd expect the custom element to work mostly the same way regardless of how it's rendered.
I'm not entirely sure why the claiming process removes all attributes in the way it does so I can't suggest a solution. Maybe if it's a custom element leaving the attributes as-is?
NOTE: To clarify this only occurs with SSR (not an SPA), and only if the elements are registered before they're claimed by Svelte. As mentioned, it's because (1) the browser parses the HTML delivered from the server, (2) the element is registered, (3) the element is "upgraded" to a custom element, and then (4) Svelte in the claiming process wipes all attrs/props by resetting them to
null
.Reproduction
https://github.com/mihar-22/svelte-custom-elements-hydration-bug
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: