Sveltekit Hydration best practices to avoid buttons that do not work when page loads ? #11836
-
Describe the problemI saw this tweet today : https://x.com/TkDodo/status/1757037627100869027?s=20
Is this a problem with Sveltekit too ? And how to avoid it ? I saw these answers :
Maybe Sveltekit does it as well ? Describe the proposed solutionMaybe use other options than SSR ?? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Yes, this can happen with SvelteKit, too - it can happen with any framework you use. The answer talking about progressive enhancement is the correct way to solve this: Make sure that your page works without JavaScript, too (to the extent possible / necessary). https://kit.svelte.dev/docs/form-actions talks about this in more detail. |
Beta Was this translation helpful? Give feedback.
-
I disable a lot of buttons on SSR, this is how I do it @MarArMar: <button
disabled={!browser || !stripe}
on:Click={doSomething}>
Buy!
{#if !browser || !stripe}
<!-- show loader -->
{/if}
</button> I style it, too.. Change the color / opacity when it's disabled. This loads the button in a "loading" state to users, but when the browser has taken over and even third party tools (like stripe.js) fully load - it's ready to go. |
Beta Was this translation helpful? Give feedback.
I disable a lot of buttons on SSR, this is how I do it @MarArMar:
I style it, too.. Change the color / opacity when it's disabled.
This loads the button in a "loading" state to users, but when the browser has taken over and even third party tools (like stripe.js) fully load - it's ready to go.