Renaming SSR Callbacks · reactwg/react-18 · Discussion #127 (original) (raw)

Heads up in the latest RC, we renamed some of the callbacks in the Node.js streaming API as well as the Web Streams API.

They're no longer called "Complete" but instead "Ready". That indicates that they're ready to be written but hasn't necessarily been written.

The Web Streams API have moved the onCompleteAll callback to a stream.allReady promise.

To wait for all Suspense boundaries to resolve before flushing:

let controller = new AbortController(); try { let stream = await renderToReadableStream( Success , { signal: controller.signal, } ); await stream.allReady; return new Response(stream, { headers: {'Content-Type': 'text/html'}, }); } catch (error) { return new Response( '

Loading...

', { status: 500, headers: {'Content-Type': 'text/html'}, } ); }

The Node.js API has onShellReady, onShellError or onAllReady callbacks.

const {pipe, abort} = renderToPipeableStream( , { onAllReady() { res.statusCode = 200; res.setHeader('Content-type', 'text/html'); pipe(res); }, onShellError(x) { res.statusCode = 500; res.send( '

Loading...

' ); } } );