@@ -10,6 +10,7 @@ const compress = require('compression');
1010const chalk = require ( 'chalk' ) ;
1111const express = require ( 'express' ) ;
1212const http = require ( 'http' ) ;
13+ const React = require ( 'react' ) ;
1314
1415const { renderToPipeableStream} = require ( 'react-dom/server' ) ;
1516const { createFromNodeStream} = require ( 'react-server-dom-esm/client' ) ;
@@ -62,20 +63,29 @@ app.all('/', async function (req, res, next) {
6263 if ( req . accepts ( 'text/html' ) ) {
6364 try {
6465 const rscResponse = await promiseForData ;
65-
6666 const moduleBaseURL = '/src' ;
6767
6868 // For HTML, we're a "client" emulator that runs the client code,
6969 // so we start by consuming the RSC payload. This needs the local file path
7070 // to load the source files from as well as the URL path for preloads.
71- const root = await createFromNodeStream (
72- rscResponse ,
73- moduleBasePath ,
74- moduleBaseURL
75- ) ;
71+
72+ let root ;
73+ let Root = ( ) => {
74+ if ( root ) {
75+ return React . use ( root ) ;
76+ }
77+
78+ return React . use (
79+ ( root = createFromNodeStream (
80+ rscResponse ,
81+ moduleBasePath ,
82+ moduleBaseURL
83+ ) )
84+ ) ;
85+ } ;
7686 // Render it into HTML by resolving the client components
7787 res . set ( 'Content-type' , 'text/html' ) ;
78- const { pipe} = renderToPipeableStream ( root , {
88+ const { pipe} = renderToPipeableStream ( React . createElement ( Root ) , {
7989 // TODO: bootstrapModules inserts a preload before the importmap which causes
8090 // the import map to be invalid. We need to fix that in Float somehow.
8191 // bootstrapModules: ['/src/index.js'],
@@ -89,6 +99,7 @@ app.all('/', async function (req, res, next) {
8999 } else {
90100 try {
91101 const rscResponse = await promiseForData ;
102+
92103 // For other request, we pass-through the RSC payload.
93104 res . set ( 'Content-type' , 'text/x-component' ) ;
94105 rscResponse . on ( 'data' , data => {
0 commit comments