-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
True equivalent to getStaticProps
?
#1599
Comments
Have you thought about using
|
Ah, to be honest I hadn’t even thought of it 🤦🏻♀️ I guess a few drawbacks that come to mind are:
To be honest I don’t really understand why If it works then I guess that’s a solution! It all does feel a bit unintuitive, and I still think a dedicated way to provide server/pretender only data would be a step forward in DX for sveltekit |
So I can confirm that the |
Also even with a Unless I'm missing something this is a potentially dealbreaking issue if there's no way to opt-out of calling |
I'm not sure about this statement. I think that it's either not true or I'm misunderstanding what you're saying. The reason SvelteKit reruns this logic on the client is that it's doing hydration. If you're not familiar with that term check out these docs I've proposed adding in one of the pending PRs. So, SvelteKit fetches data in |
Oookay that makes much more sense. I didn't realise that svelte's I am using sveltekit's I still think an SSR-only load method would be a DX improvement, but sounds like I just misunderstood how Happy to close this, unless the docs should be clarified at all. |
Same problem here: from the docs I misunderstood how So it would improve if the docs would suggest in the red box below context a suitable alternative, being:
|
Chiming in from #1660 yes I was unaware of how |
I just updated the docs essentially with the suggestion above #1599 (comment). Given that, I'll go ahead and close this in favor of #1660 which it fairly similar to this issue |
Thank you, @benmccann. Another useful bit of information is contained in the prerender section: I was not aware of the behavior of endpoints during static generation (i.e. they are running and thus retrieved content is inlined). This is actually not strictly related to the previous point, but it was relevant to my case (and I believe static generation to be quite a common case), so I'm simply leaving this info here if anyone will check this issue in the future. |
Is your feature request related to a problem? Please describe.
The
load
function currently runs on both the server and the client, which means that you can't do anything that should be left to the server in it (eg: fetching data for static rendering). Instead you have to create an endpoint route and then fetch this as json in yourload
, which is a lot of boilerplate and bloat for a very common use-case.Even with a JSON endpoint to do heavy lifting, every route on the client still has to make that request and wait for it to resolve before rendering when the page has already prerendered.
Describe the solution you'd like
A way to opt out of running
load
on the client, so it provides props either only for SSR or prerendering. I know this was previously considered for sapper, and I'd love to see it reach sveltekit. Either as an option onload
, or a new function with a similar signature, like how NextJS hasgetStaticProps
, etc.Describe alternatives you've considered
The currently recommended pattern for this use-case is creating JSON endpoints for every single route that needs data, which for a static site generator type context with a CMS is every route. Not only is that a lot of boilerplate and crappy DX, but it has unnecessary performance implications during routing outlined above.
There are other workarounds to help reduce the issue — prefetching as much as possible, using
maxage
to cache already visited routes — but none actually fix the problem that shouldn't exist in the first place.How important is this feature to you?
Unless I'm missing something this is a big drawback to using sveltekit as an SSG, which was my main use-case over the likes of NextJS and Gatsby.
The text was updated successfully, but these errors were encountered: