ConsoleTVs / sswr

🔥 Svelte stale while revalidate (SWR) data fetching strategy
MIT License
234 stars 11 forks source link

Issue during SSR, fetch not defined #6

Closed Evertt closed 3 years ago

Evertt commented 3 years ago

This issue happens in SvelteKit and I presume also in Sapper.

This issue could relatively easily be mitigated if createSWR() wasn't automatically called. Then a developer like me could choose not to call it during SSR, or to call it with a special fetcher.

asv7c2 commented 3 years ago

Same problem.

ConsoleTVs commented 3 years ago

Hey guys, can we elaborate a bit on the problem? I have never used ssr. What is the intention of it, should it automatically fetch on server first and then client?

Evertt commented 3 years ago

Yeah the idea is that it fetches on the server first so that it can deliver pre-rendered html to the client. And after that the client takes over.

So on the server I want to be able to configure swr to use node-fetch.

ConsoleTVs commented 3 years ago

Hey guys, got an update for you all.

I am no expert at SSR, and since sveltekit is still in beta I don't want to get into it.

So for now, what I made is make it work with any SSR solution but without actually fetching on the server. Instead, sswr will only fetch on the client.

Hope this fix works for your current applications. I am happy to get any PR. This library is fairly simple at the end of the day.

I've also fixed a few typescript generic paramenters. Please try version: 1.2.0

Have a nice day!