@@ -191,6 +191,34 @@ function updateForwardRef(
191
191
return workInProgress . child ;
192
192
}
193
193
194
+ function updateForwardRefLazy (
195
+ current : Fiber | null ,
196
+ workInProgress : Fiber ,
197
+ Component : any ,
198
+ renderExpirationTime : ExpirationTime ,
199
+ ) {
200
+ const props = workInProgress . pendingProps ;
201
+ const resolvedProps = resolveDefaultProps ( Component , props ) ;
202
+ if ( resolvedProps !== null ) {
203
+ workInProgress . pendingProps = resolvedProps ;
204
+ const child = updateForwardRef (
205
+ current ,
206
+ workInProgress ,
207
+ Component ,
208
+ renderExpirationTime ,
209
+ ) ;
210
+ workInProgress . pendingProps = workInProgress . memoizedProps = props ;
211
+ return child ;
212
+ } else {
213
+ return updateForwardRef (
214
+ current ,
215
+ workInProgress ,
216
+ Component ,
217
+ renderExpirationTime ,
218
+ ) ;
219
+ }
220
+ }
221
+
194
222
function updateFragment (
195
223
current : Fiber | null ,
196
224
workInProgress : Fiber ,
@@ -287,6 +315,34 @@ function updateFunctionalComponent(
287
315
return workInProgress . child ;
288
316
}
289
317
318
+ function updateFunctionalComponentLazy (
319
+ current ,
320
+ workInProgress ,
321
+ Component ,
322
+ renderExpirationTime ,
323
+ ) {
324
+ const props = workInProgress . pendingProps ;
325
+ const resolvedProps = resolveDefaultProps ( Component , props ) ;
326
+ if ( resolvedProps !== null ) {
327
+ workInProgress . pendingProps = resolvedProps ;
328
+ const child = updateFunctionalComponent (
329
+ current ,
330
+ workInProgress ,
331
+ Component ,
332
+ renderExpirationTime ,
333
+ ) ;
334
+ workInProgress . pendingProps = workInProgress . memoizedProps = props ;
335
+ return child ;
336
+ } else {
337
+ return updateFunctionalComponent (
338
+ current ,
339
+ workInProgress ,
340
+ Component ,
341
+ renderExpirationTime ,
342
+ ) ;
343
+ }
344
+ }
345
+
290
346
function updateClassComponent (
291
347
current : Fiber | null ,
292
348
workInProgress : Fiber ,
@@ -436,6 +492,34 @@ function finishClassComponent(
436
492
return workInProgress . child ;
437
493
}
438
494
495
+ function updateClassComponentLazy (
496
+ current ,
497
+ workInProgress ,
498
+ Component ,
499
+ renderExpirationTime ,
500
+ ) {
501
+ const props = workInProgress . pendingProps ;
502
+ const resolvedProps = resolveDefaultProps ( Component , props ) ;
503
+ if ( resolvedProps !== null ) {
504
+ workInProgress . pendingProps = resolvedProps ;
505
+ const child = updateClassComponent (
506
+ current ,
507
+ workInProgress ,
508
+ Component ,
509
+ renderExpirationTime ,
510
+ ) ;
511
+ workInProgress . pendingProps = workInProgress . memoizedProps = props ;
512
+ return child ;
513
+ } else {
514
+ return updateClassComponent (
515
+ current ,
516
+ workInProgress ,
517
+ Component ,
518
+ renderExpirationTime ,
519
+ ) ;
520
+ }
521
+ }
522
+
439
523
function pushHostRootContext ( workInProgress ) {
440
524
const root = ( workInProgress . stateNode : FiberRoot ) ;
441
525
if ( root . pendingContext ) {
@@ -585,6 +669,21 @@ function updateHostText(current, workInProgress) {
585
669
return null ;
586
670
}
587
671
672
+ function resolveDefaultProps ( Component , baseProps ) {
673
+ if ( Component && Component . defaultProps ) {
674
+ // Resolve default props. Taken from ReactElement
675
+ const props = Object . assign ( { } , baseProps ) ;
676
+ const defaultProps = Component . defaultProps ;
677
+ for ( let propName in defaultProps ) {
678
+ if ( props [ propName ] === undefined ) {
679
+ props [ propName ] = defaultProps [ propName ] ;
680
+ }
681
+ }
682
+ return props ;
683
+ }
684
+ return null ;
685
+ }
686
+
588
687
function mountIndeterminateComponent (
589
688
current ,
590
689
workInProgress ,
@@ -597,6 +696,7 @@ function mountIndeterminateComponent(
597
696
'likely caused by a bug in React. Please file an issue.' ,
598
697
) ;
599
698
699
+ const props = workInProgress . pendingProps ;
600
700
if (
601
701
Component !== null &&
602
702
Component !== undefined &&
@@ -606,32 +706,28 @@ function mountIndeterminateComponent(
606
706
if ( typeof Component === 'function' ) {
607
707
if ( shouldConstruct ( Component ) ) {
608
708
workInProgress . tag = ClassComponentLazy ;
609
- return updateClassComponent (
709
+ return updateClassComponentLazy (
610
710
current ,
611
711
workInProgress ,
612
712
Component ,
613
713
renderExpirationTime ,
614
714
) ;
615
715
} else {
616
- const child = mountIndeterminateComponent (
716
+ workInProgress . tag = FunctionalComponentLazy ;
717
+ return updateFunctionalComponentLazy (
617
718
current ,
618
719
workInProgress ,
619
720
Component ,
620
721
renderExpirationTime ,
621
722
) ;
622
- workInProgress . tag =
623
- workInProgress . tag === FunctionalComponent
624
- ? FunctionalComponentLazy
625
- : ClassComponentLazy ;
626
- return child ;
627
723
}
628
724
} else if (
629
725
Component !== undefined &&
630
726
Component !== null &&
631
727
Component . $$typeof
632
728
) {
633
729
workInProgress . tag = ForwardRefLazy ;
634
- return updateForwardRef (
730
+ return updateForwardRefLazy (
635
731
current ,
636
732
workInProgress ,
637
733
Component ,
@@ -640,7 +736,6 @@ function mountIndeterminateComponent(
640
736
}
641
737
}
642
738
643
- const props = workInProgress . pendingProps ;
644
739
const unmaskedContext = getUnmaskedContext ( workInProgress ) ;
645
740
const context = getMaskedContext ( workInProgress , unmaskedContext ) ;
646
741
@@ -1112,7 +1207,7 @@ function beginWork(
1112
1207
case FunctionalComponentLazy: {
1113
1208
const thenable = workInProgress . type ;
1114
1209
const Component = ( thenable . _reactResult : any ) ;
1115
- return updateFunctionalComponent (
1210
+ return updateFunctionalComponentLazy (
1116
1211
current ,
1117
1212
workInProgress ,
1118
1213
Component ,
@@ -1131,7 +1226,7 @@ function beginWork(
1131
1226
case ClassComponentLazy: {
1132
1227
const thenable = workInProgress . type ;
1133
1228
const Component = ( thenable . _reactResult : any ) ;
1134
- return updateClassComponent (
1229
+ return updateClassComponentLazy (
1135
1230
current ,
1136
1231
workInProgress ,
1137
1232
Component ,
@@ -1168,7 +1263,7 @@ function beginWork(
1168
1263
case ForwardRefLazy:
1169
1264
const thenable = workInProgress.type;
1170
1265
const Component = (thenable._reactResult: any);
1171
- return updateForwardRef (
1266
+ return updateForwardRefLazy (
1172
1267
current,
1173
1268
workInProgress,
1174
1269
Component,
0 commit comments