@@ -17,6 +17,23 @@ global.ReadableStream =
1717global . TextEncoder = require ( 'util' ) . TextEncoder ;
1818global . TextDecoder = require ( 'util' ) . TextDecoder ;
1919
20+ // Polyfill stream methods on JSDOM.
21+ global . Blob . prototype . stream = function ( ) {
22+ const impl = Object . getOwnPropertySymbols ( this ) [ 0 ] ;
23+ const buffer = this [ impl ] . _buffer ;
24+ return new ReadableStream ( {
25+ start ( c ) {
26+ c . enqueue ( new Uint8Array ( buffer ) ) ;
27+ c . close ( ) ;
28+ } ,
29+ } ) ;
30+ } ;
31+
32+ global . Blob . prototype . text = async function ( ) {
33+ const impl = Object . getOwnPropertySymbols ( this ) [ 0 ] ;
34+ return this [ impl ] . _buffer . toString ( 'utf8' ) ;
35+ } ;
36+
2037// Don't wait before processing work on the server.
2138// TODO: we can replace this with FlightServer.act().
2239global . setTimeout = cb => cb ( ) ;
@@ -975,10 +992,12 @@ describe('ReactFlightDOMForm', () => {
975992
976993 function Form ( { action} ) {
977994 const [ errorMsg , dispatch ] = useActionState ( action , null ) ;
995+ let text ;
978996 if ( errorMsg ) {
979997 blob = errorMsg ;
998+ text = React . use ( blob . text ( ) ) ;
980999 }
981- return < form action = { dispatch } / >;
1000+ return < form action = { dispatch } > { text } </ form > ;
9821001 }
9831002
9841003 const FormRef = await clientExports ( Form ) ;
@@ -1008,21 +1027,19 @@ describe('ReactFlightDOMForm', () => {
10081027 container . innerHTML = '' ;
10091028
10101029 const postbackRscStream = ReactServerDOMServer . renderToReadableStream (
1011- < FormRef action = { serverAction } /> ,
1030+ { formState , root : < FormRef action = { serverAction } /> } ,
10121031 webpackMap ,
10131032 ) ;
1014- const postbackResponse = ReactServerDOMClient . createFromReadableStream (
1015- postbackRscStream ,
1016- {
1033+ const postbackResponse =
1034+ await ReactServerDOMClient . createFromReadableStream ( postbackRscStream , {
10171035 ssrManifest : {
10181036 moduleMap : null ,
10191037 moduleLoading : null ,
10201038 } ,
1021- } ,
1022- ) ;
1039+ } ) ;
10231040 const postbackSsrStream = await ReactDOMServer . renderToReadableStream (
1024- postbackResponse ,
1025- { formState : formState } ,
1041+ postbackResponse . root ,
1042+ { formState : postbackResponse . formState } ,
10261043 ) ;
10271044 await readIntoContainer ( postbackSsrStream ) ;
10281045 }
@@ -1034,5 +1051,8 @@ describe('ReactFlightDOMForm', () => {
10341051
10351052 expect ( blob instanceof Blob ) . toBe ( true ) ;
10361053 expect ( blob . size ) . toBe ( 2 ) ;
1054+
1055+ const form2 = container . getElementsByTagName ( 'form' ) [ 0 ] ;
1056+ expect ( form2 . textContent ) . toBe ( 'hi' ) ;
10371057 } ) ;
10381058} ) ;
0 commit comments