This already works when using SWR 1.x, but SWR 2.x will no longer run on the server as it has no way of transferring the data to the client.
I understand that the way forward for SSR will be React Server Components, but this doesn't sound like a viable solution for generating static markup.
I could imagine that using a primitive like react-fetch would be a suitable option in the future, but currently react-dom/serverdoes not implement getCacheForType() so this does not work (yet?).
I guess the question boils down to this: Will there be a supported way to use Suspense for Data Fetching in an SSG context, or will we need to fetch the data outside of React with a Next.js-style getStaticProps pattern?
I'm closing this for now, as the Capri react template now uses the data loading infrastructure provided by react-router v6. The same can be achieved with TanStack Router.
We would like to use Suspense for Data Fetching in an SSG setup (Capri + React).
The idea is to use
renderToPipeableStream()
+onAllReady()
orrenderToReadableStream()
+await stream.allReady
to get the final markup after all suspense boundaries have resolved.This already works when using SWR 1.x, but SWR 2.x will no longer run on the server as it has no way of transferring the data to the client.
I understand that the way forward for SSR will be React Server Components, but this doesn't sound like a viable solution for generating static markup.
I could imagine that using a primitive like react-fetch would be a suitable option in the future, but currently
react-dom/server
does not implementgetCacheForType()
so this does not work (yet?).I guess the question boils down to this: Will there be a supported way to use Suspense for Data Fetching in an SSG context, or will we need to fetch the data outside of React with a Next.js-style
getStaticProps
pattern?