@@ -31,6 +31,7 @@ import {
31
31
Profiler ,
32
32
SuspenseComponent ,
33
33
PureComponent ,
34
+ LazyComponent ,
34
35
} from 'shared/ReactWorkTags' ;
35
36
import {
36
37
NoEffect ,
@@ -105,7 +106,6 @@ import {
105
106
createFiberFromFragment ,
106
107
createWorkInProgress ,
107
108
} from './ReactFiber' ;
108
- import { REACT_LAZY_TYPE } from 'shared/ReactSymbols' ;
109
109
110
110
const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
111
111
@@ -691,7 +691,7 @@ function resolveDefaultProps(Component, baseProps) {
691
691
return baseProps ;
692
692
}
693
693
694
- function mountIndeterminateComponent (
694
+ function mountLazyComponent (
695
695
_current ,
696
696
workInProgress ,
697
697
elementType ,
@@ -710,85 +710,94 @@ function mountIndeterminateComponent(
710
710
}
711
711
712
712
const props = workInProgress . pendingProps ;
713
- let Component ;
714
- if (
715
- typeof elementType === 'object' &&
716
- elementType !== null &&
717
- elementType . $$typeof === REACT_LAZY_TYPE
718
- ) {
719
- // We can't start a User Timing measurement with correct label yet.
720
- // Cancel and resume right after we know the tag.
721
- cancelWorkTimer ( workInProgress ) ;
722
- Component = readLazyComponentType ( elementType ) ;
723
- // Store the unwrapped component in the type.
724
- workInProgress . type = Component ;
725
- const resolvedTag = ( workInProgress . tag = resolveLazyComponentTag (
726
- workInProgress ,
727
- Component ,
728
- ) ) ;
729
- startWorkTimer ( workInProgress ) ;
730
- const resolvedProps = resolveDefaultProps ( Component , props ) ;
731
- let child ;
732
- switch ( resolvedTag ) {
733
- case FunctionComponent : {
734
- child = updateFunctionComponent (
735
- null ,
736
- workInProgress ,
737
- Component ,
738
- resolvedProps ,
739
- renderExpirationTime ,
740
- ) ;
741
- break ;
742
- }
743
- case ClassComponent : {
744
- child = updateClassComponent (
745
- null ,
746
- workInProgress ,
747
- Component ,
748
- resolvedProps ,
749
- renderExpirationTime ,
750
- ) ;
751
- break ;
752
- }
753
- case ForwardRef : {
754
- child = updateForwardRef (
755
- null ,
756
- workInProgress ,
757
- Component ,
758
- resolvedProps ,
759
- renderExpirationTime ,
760
- ) ;
761
- break ;
762
- }
763
- case PureComponent : {
764
- child = updatePureComponent (
765
- null ,
766
- workInProgress ,
767
- Component ,
768
- resolvedProps ,
769
- updateExpirationTime ,
770
- renderExpirationTime ,
771
- ) ;
772
- break ;
773
- }
774
- default : {
775
- // This message intentionally doesn't metion ForwardRef or PureComponent
776
- // because the fact that it's a separate type of work is an
777
- // implementation detail.
778
- invariant (
779
- false ,
780
- 'Element type is invalid. Received a promise that resolves to: %s. ' +
781
- 'Promise elements must resolve to a class or function.' ,
782
- Component ,
783
- ) ;
784
- }
713
+ // We can't start a User Timing measurement with correct label yet.
714
+ // Cancel and resume right after we know the tag.
715
+ cancelWorkTimer ( workInProgress ) ;
716
+ let Component = readLazyComponentType ( elementType ) ;
717
+ // Store the unwrapped component in the type.
718
+ workInProgress . type = Component ;
719
+ const resolvedTag = ( workInProgress . tag = resolveLazyComponentTag (
720
+ workInProgress ,
721
+ Component ,
722
+ ) ) ;
723
+ startWorkTimer ( workInProgress ) ;
724
+ const resolvedProps = resolveDefaultProps ( Component , props ) ;
725
+ let child ;
726
+ switch ( resolvedTag ) {
727
+ case FunctionComponent : {
728
+ child = updateFunctionComponent (
729
+ null ,
730
+ workInProgress ,
731
+ Component ,
732
+ resolvedProps ,
733
+ renderExpirationTime ,
734
+ ) ;
735
+ break ;
785
736
}
786
- return child ;
787
- } else {
788
- workInProgress . type = elementType ;
789
- Component = elementType ;
737
+ case ClassComponent : {
738
+ child = updateClassComponent (
739
+ null ,
740
+ workInProgress ,
741
+ Component ,
742
+ resolvedProps ,
743
+ renderExpirationTime ,
744
+ ) ;
745
+ break ;
746
+ }
747
+ case ForwardRef : {
748
+ child = updateForwardRef (
749
+ null ,
750
+ workInProgress ,
751
+ Component ,
752
+ resolvedProps ,
753
+ renderExpirationTime ,
754
+ ) ;
755
+ break ;
756
+ }
757
+ case PureComponent : {
758
+ child = updatePureComponent (
759
+ null ,
760
+ workInProgress ,
761
+ Component ,
762
+ resolvedProps ,
763
+ updateExpirationTime ,
764
+ renderExpirationTime ,
765
+ ) ;
766
+ break ;
767
+ }
768
+ default : {
769
+ // This message intentionally doesn't metion ForwardRef or PureComponent
770
+ // because the fact that it's a separate type of work is an
771
+ // implementation detail.
772
+ invariant (
773
+ false ,
774
+ 'Element type is invalid. Received a promise that resolves to: %s. ' +
775
+ 'Promise elements must resolve to a class or function.' ,
776
+ Component ,
777
+ ) ;
778
+ }
779
+ }
780
+ return child ;
781
+ }
782
+
783
+ function mountIndeterminateComponent (
784
+ _current ,
785
+ workInProgress ,
786
+ Component ,
787
+ renderExpirationTime ,
788
+ ) {
789
+ if ( _current !== null ) {
790
+ // An indeterminate component only mounts if it suspended inside a non-
791
+ // concurrent tree, in an inconsistent state. We want to tree it like
792
+ // a new mount, even though an empty version of it already committed.
793
+ // Disconnect the alternate pointers.
794
+ _current . alternate = null ;
795
+ workInProgress . alternate = null ;
796
+ // Since this is conceptually a new fiber, schedule a Placement effect
797
+ workInProgress . effectTag |= Placement ;
790
798
}
791
799
800
+ const props = workInProgress . pendingProps ;
792
801
const unmaskedContext = getUnmaskedContext ( workInProgress , Component , false ) ;
793
802
const context = getMaskedContext ( workInProgress , unmaskedContext ) ;
794
803
@@ -1443,6 +1452,15 @@ function beginWork(
1443
1452
case IndeterminateComponent : {
1444
1453
const elementType = workInProgress . elementType ;
1445
1454
return mountIndeterminateComponent (
1455
+ current ,
1456
+ workInProgress ,
1457
+ elementType ,
1458
+ renderExpirationTime ,
1459
+ ) ;
1460
+ }
1461
+ case LazyComponent : {
1462
+ const elementType = workInProgress . elementType ;
1463
+ return mountLazyComponent (
1446
1464
current ,
1447
1465
workInProgress ,
1448
1466
elementType ,
0 commit comments