@@ -184,6 +184,43 @@ describe('ReactFlight', () => {
184
184
) ;
185
185
} ) ;
186
186
187
+ it ( 'errors on a Lazy element being used in Component position' , async ( ) => {
188
+ function SharedComponent ( { text} ) {
189
+ return (
190
+ < div >
191
+ shared< span > { text } </ span >
192
+ </ div >
193
+ ) ;
194
+ }
195
+
196
+ let load = null ;
197
+
198
+ const LazyElementDisguisedAsComponent = React . lazy ( ( ) => {
199
+ return new Promise ( res => {
200
+ load = ( ) => res ( { default : < SharedComponent text = { 'a' } /> } ) ;
201
+ } ) ;
202
+ } ) ;
203
+
204
+ function ServerComponent ( ) {
205
+ return (
206
+ < React . Suspense fallback = { 'Loading...' } >
207
+ < LazyElementDisguisedAsComponent text = { 'b' } />
208
+ </ React . Suspense >
209
+ ) ;
210
+ }
211
+
212
+ const transport = ReactNoopFlightServer . render ( < ServerComponent /> ) ;
213
+
214
+ act ( ( ) => {
215
+ const rootModel = ReactNoopFlightClient . read ( transport ) ;
216
+ ReactNoop . render ( rootModel ) ;
217
+ } ) ;
218
+ expect ( ReactNoop ) . toMatchRenderedOutput ( 'Loading...' ) ;
219
+ spyOnDevAndProd ( console , 'error' ) ;
220
+ await load ( ) ;
221
+ expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
222
+ } ) ;
223
+
187
224
it ( 'can render a lazy element' , async ( ) => {
188
225
function SharedComponent ( { text} ) {
189
226
return (
@@ -229,6 +266,43 @@ describe('ReactFlight', () => {
229
266
) ;
230
267
} ) ;
231
268
269
+ it ( 'errors with lazy value in element position that resolves to Component' , async ( ) => {
270
+ function SharedComponent ( { text} ) {
271
+ return (
272
+ < div >
273
+ shared< span > { text } </ span >
274
+ </ div >
275
+ ) ;
276
+ }
277
+
278
+ let load = null ;
279
+
280
+ const componentDisguisedAsElement = React . lazy ( ( ) => {
281
+ return new Promise ( res => {
282
+ load = ( ) => res ( { default : SharedComponent } ) ;
283
+ } ) ;
284
+ } ) ;
285
+
286
+ function ServerComponent ( ) {
287
+ return (
288
+ < React . Suspense fallback = { 'Loading...' } >
289
+ { componentDisguisedAsElement }
290
+ </ React . Suspense >
291
+ ) ;
292
+ }
293
+
294
+ const transport = ReactNoopFlightServer . render ( < ServerComponent /> ) ;
295
+
296
+ act ( ( ) => {
297
+ const rootModel = ReactNoopFlightClient . read ( transport ) ;
298
+ ReactNoop . render ( rootModel ) ;
299
+ } ) ;
300
+ expect ( ReactNoop ) . toMatchRenderedOutput ( 'Loading...' ) ;
301
+ spyOnDevAndProd ( console , 'error' ) ;
302
+ await load ( ) ;
303
+ expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
304
+ } ) ;
305
+
232
306
it ( 'can render a lazy module reference' , async ( ) => {
233
307
function ClientComponent ( ) {
234
308
return < div > I am client</ div > ;
0 commit comments