Skip to content

[react] Suspense for Data Fetching + Static Site Generation? #39

@fgnass

Description

@fgnass

We would like to use Suspense for Data Fetching in an SSG setup (Capri + React).

The idea is to use renderToPipeableStream() + onAllReady() or
renderToReadableStream() + 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/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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions