@@ -6,6 +6,7 @@ import * as React from 'react';
66import * as PropTypes from 'prop-types' ;
77import streamServerRenderedReactComponent from '../src/streamServerRenderedReactComponent.ts' ;
88import * as ComponentRegistry from '../src/ComponentRegistry.ts' ;
9+ import ReactOnRails from '../src/ReactOnRails.node.ts' ;
910
1011const AsyncContent = async ( { throwAsyncError } ) => {
1112 await new Promise ( ( resolve ) => {
@@ -64,29 +65,29 @@ describe('streamServerRenderedReactComponent', () => {
6465 } = { } ) => {
6566 switch ( componentType ) {
6667 case 'reactComponent' :
67- ComponentRegistry . register ( { TestComponentForStreaming } ) ;
68+ ReactOnRails . register ( { TestComponentForStreaming } ) ;
6869 break ;
6970 case 'renderFunction' :
70- ComponentRegistry . register ( {
71+ ReactOnRails . register ( {
7172 TestComponentForStreaming : ( props , _railsContext ) => ( ) => < TestComponentForStreaming { ...props } /> ,
7273 } ) ;
7374 break ;
7475 case 'asyncRenderFunction' :
75- ComponentRegistry . register ( {
76+ ReactOnRails . register ( {
7677 TestComponentForStreaming : ( props , _railsContext ) => ( ) =>
7778 Promise . resolve ( < TestComponentForStreaming { ...props } /> ) ,
7879 } ) ;
7980 break ;
8081 case 'erroneousRenderFunction' :
81- ComponentRegistry . register ( {
82+ ReactOnRails . register ( {
8283 TestComponentForStreaming : ( _props , _railsContext ) => {
8384 // The error happen inside the render function itself not inside the returned React component
8485 throw new Error ( 'Sync Error from render function' ) ;
8586 } ,
8687 } ) ;
8788 break ;
8889 case 'erroneousAsyncRenderFunction' :
89- ComponentRegistry . register ( {
90+ ReactOnRails . register ( {
9091 TestComponentForStreaming : ( _props , _railsContext ) =>
9192 // The error happen inside the render function itself not inside the returned React component
9293 Promise . reject ( new Error ( 'Async Error from render function' ) ) ,
@@ -101,6 +102,11 @@ describe('streamServerRenderedReactComponent', () => {
101102 trace : false ,
102103 props : { throwSyncError, throwAsyncError } ,
103104 throwJsErrors,
105+ railsContext : {
106+ componentSpecificMetadata : {
107+ renderRequestId : '123' ,
108+ } ,
109+ } ,
104110 } ) ;
105111
106112 const chunks = [ ] ;
@@ -173,13 +179,15 @@ describe('streamServerRenderedReactComponent', () => {
173179 expect ( chunks . length ) . toBeGreaterThanOrEqual ( 2 ) ;
174180 expect ( chunks [ 0 ] . html ) . toContain ( 'Header In The Shell' ) ;
175181 expect ( chunks [ 0 ] . consoleReplayScript ) . toBe ( '' ) ;
176- expect ( chunks [ 0 ] . hasErrors ) . toBe ( false ) ;
177182 expect ( chunks [ 0 ] . isShellReady ) . toBe ( true ) ;
178183 // Script that fallbacks the render to client side
179184 expect ( chunks [ 1 ] . html ) . toMatch ( / t h e s e r v e r r e n d e r i n g e r r o r e d : \\ n \\ n A s y n c E r r o r / ) ;
180185 expect ( chunks [ 1 ] . consoleReplayScript ) . toBe ( '' ) ;
181- expect ( chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
182186 expect ( chunks [ 1 ] . isShellReady ) . toBe ( true ) ;
187+
188+ // One of the chunks should have a hasErrors property of true
189+ expect ( chunks [ 0 ] . hasErrors || chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
190+ expect ( chunks [ 0 ] . hasErrors && chunks [ 1 ] . hasErrors ) . toBe ( false ) ;
183191 } ) ;
184192
185193 it ( "doesn't emit an error if there is an error in the async content and throwJsErrors is false" , async ( ) => {
@@ -194,13 +202,15 @@ describe('streamServerRenderedReactComponent', () => {
194202 expect ( chunks . length ) . toBeGreaterThanOrEqual ( 2 ) ;
195203 expect ( chunks [ 0 ] . html ) . toContain ( 'Header In The Shell' ) ;
196204 expect ( chunks [ 0 ] . consoleReplayScript ) . toBe ( '' ) ;
197- expect ( chunks [ 0 ] . hasErrors ) . toBe ( false ) ;
198205 expect ( chunks [ 0 ] . isShellReady ) . toBe ( true ) ;
199206 // Script that fallbacks the render to client side
200207 expect ( chunks [ 1 ] . html ) . toMatch ( / t h e s e r v e r r e n d e r i n g e r r o r e d : \\ n \\ n A s y n c E r r o r / ) ;
201208 expect ( chunks [ 1 ] . consoleReplayScript ) . toBe ( '' ) ;
202- expect ( chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
203209 expect ( chunks [ 1 ] . isShellReady ) . toBe ( true ) ;
210+
211+ // One of the chunks should have a hasErrors property of true
212+ expect ( chunks [ 0 ] . hasErrors || chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
213+ expect ( chunks [ 0 ] . hasErrors && chunks [ 1 ] . hasErrors ) . toBe ( false ) ;
204214 } ) ;
205215
206216 it . each ( [ 'asyncRenderFunction' , 'renderFunction' ] ) (
@@ -250,12 +260,14 @@ describe('streamServerRenderedReactComponent', () => {
250260 expect ( chunks . length ) . toBeGreaterThanOrEqual ( 2 ) ;
251261 expect ( chunks [ 0 ] . html ) . toContain ( 'Header In The Shell' ) ;
252262 expect ( chunks [ 0 ] . consoleReplayScript ) . toBe ( '' ) ;
253- expect ( chunks [ 0 ] . hasErrors ) . toBe ( false ) ;
254263 expect ( chunks [ 0 ] . isShellReady ) . toBe ( true ) ;
255264 expect ( chunks [ 1 ] . html ) . toMatch ( / t h e s e r v e r r e n d e r i n g e r r o r e d : \\ n \\ n A s y n c E r r o r / ) ;
256265 expect ( chunks [ 1 ] . consoleReplayScript ) . toBe ( '' ) ;
257- expect ( chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
258266 expect ( chunks [ 1 ] . isShellReady ) . toBe ( true ) ;
267+
268+ // One of the chunks should have a hasErrors property of true
269+ expect ( chunks [ 0 ] . hasErrors || chunks [ 1 ] . hasErrors ) . toBe ( true ) ;
270+ expect ( chunks [ 0 ] . hasErrors && chunks [ 1 ] . hasErrors ) . toBe ( false ) ;
259271 } ,
260272 ) ;
261273
@@ -308,13 +320,18 @@ describe('streamServerRenderedReactComponent', () => {
308320
309321 it ( 'streams a string from a Promise that resolves to a string' , async ( ) => {
310322 const StringPromiseComponent = ( ) => Promise . resolve ( '<div>String from Promise</div>' ) ;
311- ComponentRegistry . register ( { StringPromiseComponent } ) ;
323+ ReactOnRails . register ( { StringPromiseComponent } ) ;
312324
313325 const renderResult = streamServerRenderedReactComponent ( {
314326 name : 'StringPromiseComponent' ,
315327 domNodeId : 'stringPromiseId' ,
316328 trace : false ,
317329 throwJsErrors : false ,
330+ railsContext : {
331+ componentSpecificMetadata : {
332+ renderRequestId : '123' ,
333+ } ,
334+ } ,
318335 } ) ;
319336
320337 const chunks = [ ] ;
0 commit comments