Open sukeshpabolu opened 2 months ago
One thing we could do here is detect a custom-element as the parent at compile time and insert different DOM traversal methods that allow for things like <style>
elements that might occur between.
There also have been issues with web components + hydration in Svelte 4, where attributes were adjusted before the hydration came across it. It's definetly a tricky area, and something where a bit more robustness/"leave it alone" wouldn't hurt.
I'm testing this a bit and it doesn't seem to ever worked in any version of svelte 5, it's throwing some version of this hydration error since the beginning.
Sound about right - would've been surprised that this ever worked. Giving this the 5.x milestone, but if someone wants to fix it before 5.0 they're welcome to.
I'm testing this a bit and it doesn't seem to ever worked in any version of svelte 5, it's throwing some version of this hydration error since the beginning.
It worked in 178. If you can suggest a temp fix that will be good atleast
I'm testing this a bit and it doesn't seem to ever worked in any version of svelte 5, it's throwing some version of this hydration error since the beginning.
It worked in 178. If you can suggest a temp fix that will be good atleast
This is in your reproduction, installing svelte@5.0.0-next.178
...as you can see the error about hydration is still there. Did it behave differently than the latest versions?
Ok now i think i get what you are saying @SukeshP1995 ...after 179 the whole app goes blank, before it was showing. The problem however is that your custom element is still not hydrated properly so whatever svelte code is inside or even after your custom element will not work properly.
I'm testing this a bit and it doesn't seem to ever worked in any version of svelte 5, it's throwing some version of this hydration error since the beginning.
It worked in 178. If you can suggest a temp fix that will be good atleast
Speaking of this i have to admit i never actually worked extensively with web components but if i can have an intuition about what you are trying to do with lightStyleCss
is to add some css for the light dom right? If so this doesn't cause hydration issues even in the latest version of svelte
connectedCallback() {
const lightStyles = document.createElement('style');
lightStyles.slot = 'light-styles';
lightStyles.innerHTML = lightStyleSheet;
- this.append(lightStyles.cloneNode(true));
+ document.head.append(lightStyles.cloneNode(true));
}
but again i don't know if this is feasible
I still believe my post above should resolve this.
I still believe my post above should resolve this.
Hi, the web components are in a package (private). If it had been my own I would have found a different way to inject those styles
I'm testing this a bit and it doesn't seem to ever worked in any version of svelte 5, it's throwing some version of this hydration error since the beginning.
It worked in 178. If you can suggest a temp fix that will be good atleast
Speaking of this i have to admit i never actually worked extensively with web components but if i can have an intuition about what you are trying to do with
lightStyleCss
is to add some css for the light dom right? If so this doesn't cause hydration issues even in the latest version of svelteconnectedCallback() { const lightStyles = document.createElement('style'); lightStyles.slot = 'light-styles'; lightStyles.innerHTML = lightStyleSheet; - this.append(lightStyles.cloneNode(true)); + document.head.append(lightStyles.cloneNode(true)); }
but again i don't know if this is feasible
I will try this and see, but FYI the web components are in a seperate internal package so I have to patch those then
I will try this and see, but FYI the web components are in a seperate internal package so I have to patch those then
Yeah i've imagined that...unfortunately hydration requires the order of elements to be consistent between SSR and the hydration phase...we can see if we can implement what Dominic proposed but until then you might need to find ways around it. :(
I will try this and see, but FYI the web components are in a seperate internal package so I have to patch those then
Yeah i've imagined that...unfortunately hydration requires the order of elements to be consistent between SSR and the hydration phase...we can see if we can implement what Dominic proposed but until then you might need to find ways around it. :(
I started pnpm patching my web components 😩. (they are only 4 of them)
What about adoptedStyleSheets
? It inserts styles without creating a node in the DOM.
connectedCallback() {
const sheet = new CSSStyleSheet();
sheet.replaceSync(lightStyleSheet);
// add styles to the closest shadowRoot or document
this.getRootNode().adoptedStyleSheets = [sheet];
}
It's even recommended to hoist sheet
to re-use it.
Every time I use the component it is creating the style tag. I am having a bunch of style tags now 🤣
Describe the bug
Facing Uncaught (in promise) HierarchyRequestError: Failed to execute 'appendChild' on 'Node': This node type does not support this method. when style element is included as first child of custom element
Reproduction
here
Logs
System Info
Severity
blocking an upgrade