resumeAndPrerender – React (original) (raw)

resumeAndPrerender continues a prerendered React tree to a static HTML string using a Web Stream.


const { prelude,postpone } = await resumeAndPrerender(reactNode, postponedState, options?)

Note


Reference

resumeAndPrerender(reactNode, postponedState, options?)

Call resumeAndPrerender to continue a prerendered React tree to a static HTML string.


import { resumeAndPrerender } from 'react-dom/static';

import { getPostponedState } from 'storage';

async function handler(request, response) {

const postponedState = getPostponedState(request);

const { prelude } = await resumeAndPrerender(<App />, postponedState, {

bootstrapScripts: ['/main.js']

});

return new Response(prelude, {

headers: { 'content-type': 'text/html' },

});

}

On the client, call hydrateRoot to make the server-generated HTML interactive.

See more examples below.

Parameters

Returns

prerender returns a Promise:

Caveats

nonce is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with CSP it would be inappropriate and insecure to include the nonce value in the prerender itself.

Note

When should I use resumeAndPrerender?

The static resumeAndPrerender API is used for static server-side generation (SSG). Unlike renderToString, resumeAndPrerender waits for all data to load before resolving. This makes it suitable for generating static HTML for a full page, including data that needs to be fetched using Suspense. To stream content as it loads, use a streaming server-side render (SSR) API like renderToReadableStream.

resumeAndPrerender can be aborted and later either continued with another resumeAndPrerender or resumed with resume to support partial pre-rendering.


Usage

Further reading

resumeAndPrerender behaves similarly to prerender but can be used to continue a previously started prerendering process that was aborted. For more information about resuming a prerendered tree, see the resume documentation.