@@ -32,6 +32,7 @@ let ReactDOMClient;
3232let ReactServerDOMServer ;
3333let ReactServerDOMClient ;
3434let ReactDOMFizzServer ;
35+ let ReactDOMStaticServer ;
3536let Suspense ;
3637let ErrorBoundary ;
3738let JSDOM ;
@@ -71,6 +72,7 @@ describe('ReactFlightDOM', () => {
7172 Suspense = React . Suspense ;
7273 ReactDOMClient = require ( 'react-dom/client' ) ;
7374 ReactDOMFizzServer = require ( 'react-dom/server.node' ) ;
75+ ReactDOMStaticServer = require ( 'react-dom/static.node' ) ;
7476 ReactServerDOMClient = require ( 'react-server-dom-webpack/client' ) ;
7577
7678 ErrorBoundary = class extends React . Component {
@@ -1300,6 +1302,91 @@ describe('ReactFlightDOM', () => {
13001302 expect ( getMeaningfulChildren ( container ) ) . toEqual ( < p > hello world</ p > ) ;
13011303 } ) ;
13021304
1305+ // @gate enablePostpone
1306+ it ( 'should allow postponing in Flight through a serialized promise' , async ( ) => {
1307+ const Context = React . createContext ( ) ;
1308+ const ContextProvider = Context . Provider ;
1309+
1310+ function Foo ( ) {
1311+ const value = React . use ( React . useContext ( Context ) ) ;
1312+ return < span > { value } </ span > ;
1313+ }
1314+
1315+ const ClientModule = clientExports ( {
1316+ ContextProvider,
1317+ Foo,
1318+ } ) ;
1319+
1320+ async function getFoo ( ) {
1321+ React . unstable_postpone ( 'foo' ) ;
1322+ }
1323+
1324+ function App ( ) {
1325+ return (
1326+ < ClientModule . ContextProvider value = { getFoo ( ) } >
1327+ < div >
1328+ < Suspense fallback = "loading..." >
1329+ < ClientModule . Foo />
1330+ </ Suspense >
1331+ </ div >
1332+ </ ClientModule . ContextProvider >
1333+ ) ;
1334+ }
1335+
1336+ const { writable, readable} = getTestStream ( ) ;
1337+
1338+ const { pipe} = ReactServerDOMServer . renderToPipeableStream (
1339+ < App /> ,
1340+ webpackMap ,
1341+ ) ;
1342+ pipe ( writable ) ;
1343+
1344+ let response = null ;
1345+ function getResponse ( ) {
1346+ if ( response === null ) {
1347+ response = ReactServerDOMClient . createFromReadableStream ( readable ) ;
1348+ }
1349+ return response ;
1350+ }
1351+
1352+ function Response ( ) {
1353+ return getResponse ( ) ;
1354+ }
1355+
1356+ const errors = [ ] ;
1357+ function onError ( error , errorInfo ) {
1358+ errors . push ( error , errorInfo ) ;
1359+ }
1360+ const result = await ReactDOMStaticServer . prerenderToNodeStream (
1361+ < Response /> ,
1362+ {
1363+ onError,
1364+ } ,
1365+ ) ;
1366+
1367+ const prelude = await new Promise ( ( resolve , reject ) => {
1368+ let content = '' ;
1369+ result . prelude . on ( 'data' , chunk => {
1370+ content += Buffer . from ( chunk ) . toString ( 'utf8' ) ;
1371+ } ) ;
1372+ result . prelude . on ( 'error' , error => {
1373+ reject ( error ) ;
1374+ } ) ;
1375+ result . prelude . on ( 'end' , ( ) => resolve ( content ) ) ;
1376+ } ) ;
1377+
1378+ expect ( errors ) . toEqual ( [ ] ) ;
1379+ const doc = new JSDOM ( prelude ) . window . document ;
1380+ expect ( getMeaningfulChildren ( doc ) ) . toEqual (
1381+ < html >
1382+ < head />
1383+ < body >
1384+ < div > loading...</ div >
1385+ </ body >
1386+ </ html > ,
1387+ ) ;
1388+ } ) ;
1389+
13031390 it ( 'should support float methods when rendering in Fizz' , async ( ) => {
13041391 function Component ( ) {
13051392 return < p > hello world</ p > ;
0 commit comments