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 an function that uses random number generation (currently Math.random) that I want to use with SvelteKit during SSR.
As far as I can tell I have two suboptimal choices:
Put it in +page.tsload. In that case it gets rerun on the client causing the random value to change, which creates an unpleasant change in the page content after hydration.
Put it in +page.server.tsload. In that case I end up making an unnecessary request to the server during every client side navigation.
Is there a solution that allows me to avoid these drawbacks i.e. not make extra requests to the server but also not render the page twice with different values on initial load?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an function that uses random number generation (currently
Math.random
) that I want to use with SvelteKit during SSR.As far as I can tell I have two suboptimal choices:
+page.ts
load
. In that case it gets rerun on the client causing the random value to change, which creates an unpleasant change in the page content after hydration.+page.server.ts
load
. In that case I end up making an unnecessary request to the server during every client side navigation.Is there a solution that allows me to avoid these drawbacks i.e. not make extra requests to the server but also not render the page twice with different values on initial load?
Beta Was this translation helpful? Give feedback.
All reactions