Setup retries for SSR/CSR
Some facts:
- All my api calls are GET to pull data from my CMS. We don't invalidate/refetch. The staleTime is Infinity. If user wants to get "fresher" data they need to reload the page, easy.
- We use ky and tanstack query.
- In our current app, ky is setup as retry FALSE, and queryClient retries as 3.
Questions:
We're moving to SSR as much as we can for SEO purposes so basically our api calls would happen JUST on the server.
1) Do we need to setup ky to retry 2/3 because this will happen on the server? And if the api calls we want the retry on the server.
2) any recommended approach for this use case where our staleTime is infinity but if there is an error fetching data on the server we want to retry to send a html with data.
4 Replies
adverse-sapphire•2mo ago
why do you need that retry at all? is the API that unreliable?
can you give more details about 2) ?
sensitive-blueOP•2mo ago
No. The CMS API receives the same requests always, but when we will do SSR could be a timeout for slow internet or stuff like that (for the end user) . Maybe should we use retry false for both(ky/query) but if we do that we won't retry the cms call if something goes wrong?
If staleTime is infinity that means doesn't make sense to have retry on queryClient ?
The flow I want is: or tanstack start gets a request for a route => calls CMS API and fails => retry 1/2 more times => it gets the data => return the html document to the client
adverse-sapphire•2mo ago
i dont understand why you would need the retry
if your end user has slow internet, that does not affect your start-server-to-your-api-server communication
sensitive-blueOP•2mo ago
I had issues of timeouts with other apis not this one. So it's not necessary then