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 have a component that is trying to generate some styles through some JS logic and then wants to populate the head element with those styles. The issue is that I want to only populate the head with these styles if the component is actually rendered so the head element doesn't get filled with useless styles. So I thought with my self that I should do what I've been doing up to now for other similar cases. Generate the styles and then put them inside of a <svelte:head> element using {at html} but this time inside the component instead of the +page. But I found out that the <svelte:head> element runs for every instance of the component which meant that If 5 instances of the component where rendered through out the code base, then 5 similar style tags would be in the head element which is not good.
Trying to workaround this issue by adding the style tag manually to the document.head doesn't work as well as <svelte:head> because the source html returned from SvelteKit doesn't have my custom style tag in its head element, which can result in a flash of unstyled content.
So I was wondering if its possible to have a <svelte:head> element that runs only once for each component as modules like <script module> tag do.
I will also appreciate any suggestions for a workaround for this issue.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered:
Thanks to you I managed to fix my issue But i still wonder whether we can have something like <svelte:head module> that can do all of this like <script module> does. It would be a cool addition in my opinion. Specially in cases like mine where you would want to create a module from this procedure to avoid having to repeat it for every single component that uses some sort of css in js, which can lead to a bit more coding.
Describe the problem
I have a component that is trying to generate some styles through some JS logic and then wants to populate the head element with those styles. The issue is that I want to only populate the head with these styles if the component is actually rendered so the head element doesn't get filled with useless styles. So I thought with my self that I should do what I've been doing up to now for other similar cases. Generate the styles and then put them inside of a <svelte:head> element using {at html} but this time inside the component instead of the +page. But I found out that the <svelte:head> element runs for every instance of the component which meant that If 5 instances of the component where rendered through out the code base, then 5 similar style tags would be in the head element which is not good.
Test.svelte
+page.svelte
Describe the proposed solution
Trying to workaround this issue by adding the style tag manually to the document.head doesn't work as well as <svelte:head> because the source html returned from SvelteKit doesn't have my custom style tag in its head element, which can result in a flash of unstyled content.
So I was wondering if its possible to have a <svelte:head> element that runs only once for each component as modules like <script module> tag do.
I will also appreciate any suggestions for a workaround for this issue.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: