18
import {
19
IndeterminateComponent,
20
FunctionComponent,
21
- FunctionComponentLazy,
21
ClassComponent,
23
- ClassComponentLazy,
22
HostRoot,
23
HostComponent,
24
HostText,
25
HostPortal,
26
ForwardRef,
29
- ForwardRefLazy,
27
Fragment,
28
Mode,
29
ContextProvider,
31
Profiler,
32
SuspenseComponent,
33
PureComponent,
37
- PureComponentLazy,
34
+ LazyComponent,
35
} from 'shared/ReactWorkTags';
36
import {
37
NoEffect,
101
updateClassInstance,
102
} from './ReactFiberClassComponent';
103
import {readLazyComponentType} from './ReactFiberLazyComponent';
107
-import {getResultFromResolvedLazyComponent} from 'shared/ReactLazyComponent';
104
import {
105
resolveLazyComponentTag,
106
createFiberFromFragment,
107
createWorkInProgress,
108
} from './ReactFiber';
113
-import {REACT_LAZY_TYPE} from 'shared/ReactSymbols';
109
110
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
111
700
return baseProps;
701
}
702
708
-function mountIndeterminateComponent(
703
+function mountLazyComponent(
704
_current,
705
workInProgress,
711
- Component,
706
+ elementType,
707
updateExpirationTime,
708
renderExpirationTime,
709
) {
719
}
720
721
const props = workInProgress.pendingProps;
727
- if (
728
- typeof Component === 'object' &&
729
- Component !== null &&
730
- Component.$$typeof === REACT_LAZY_TYPE
731
- ) {
732
- // We can't start a User Timing measurement with correct label yet.
733
- // Cancel and resume right after we know the tag.
734
- cancelWorkTimer(workInProgress);
735
- Component = readLazyComponentType(Component);
736
- const resolvedTag = (workInProgress.tag = resolveLazyComponentTag(
737
- workInProgress,
738
- Component,
739
- ));
740
- startWorkTimer(workInProgress);
741
- const resolvedProps = resolveDefaultProps(Component, props);
742
- let child;
743
- switch (resolvedTag) {
744
- case FunctionComponentLazy: {
745
- child = updateFunctionComponent(
746
- null,
747
- workInProgress,
748
- Component,
749
- resolvedProps,
750
- renderExpirationTime,
751
- );
752
- break;
753
- }
754
- case ClassComponentLazy: {
755
- child = updateClassComponent(
756
- null,
757
- workInProgress,
758
- Component,
759
- resolvedProps,
760
- renderExpirationTime,
761
- );
762
- break;
763
- }
764
- case ForwardRefLazy: {
765
- child = updateForwardRef(
766
- null,
767
- workInProgress,
768
- Component,
769
- resolvedProps,
770
- renderExpirationTime,
771
- );
772
- break;
773
- }
774
- case PureComponentLazy: {
775
- child = updatePureComponent(
776
- null,
777
- workInProgress,
778
- Component,
779
- resolvedProps,
780
- updateExpirationTime,
781
- renderExpirationTime,
782
- );
783
- break;
784
- }
785
- default: {
786
- // This message intentionally doesn't metion ForwardRef or PureComponent
787
- // because the fact that it's a separate type of work is an
788
- // implementation detail.
789
- invariant(
790
- false,
791
- 'Element type is invalid. Received a promise that resolves to: %s. ' +
792
- 'Promise elements must resolve to a class or function.',
793
- Component,
794
- );
795
- }
722
+ // We can't start a User Timing measurement with correct label yet.
723
+ // Cancel and resume right after we know the tag.
724
+ cancelWorkTimer(workInProgress);
725
+ let Component = readLazyComponentType(elementType);
726
+ // Store the unwrapped component in the type.
727
+ workInProgress.type = Component;
728
+ const resolvedTag = (workInProgress.tag = resolveLazyComponentTag(
729
+ workInProgress,
730
+ Component,
731
+ ));
732
+ startWorkTimer(workInProgress);
733
+ const resolvedProps = resolveDefaultProps(Component, props);
734
+ let child;
735
+ switch (resolvedTag) {
736
+ case FunctionComponent: {
737
+ child = updateFunctionComponent(
738
+ null,
739
+ workInProgress,
740
+ Component,
741
+ resolvedProps,
742
+ renderExpirationTime,
743
+ );
744
+ break;
745
+ }
746
+ case ClassComponent: {
747
+ child = updateClassComponent(
748
+ null,
749
+ workInProgress,
750
+ Component,
751
+ resolvedProps,
752
+ renderExpirationTime,
753
+ );
754
+ break;
755
+ }
756
+ case ForwardRef: {
757
+ child = updateForwardRef(
758
+ null,
759
+ workInProgress,
760
+ Component,
761
+ resolvedProps,
762
+ renderExpirationTime,
763
+ );
764
+ break;
765
+ }
766
+ case PureComponent: {
767
+ child = updatePureComponent(
768
+ null,
769
+ workInProgress,
770
+ Component,
771
+ resolvedProps,
772
+ updateExpirationTime,
773
+ renderExpirationTime,
774
+ );
775
+ break;
776
+ }
777
+ default: {
778
+ // This message intentionally doesn't metion ForwardRef or PureComponent
779
+ // because the fact that it's a separate type of work is an
780
+ // implementation detail.
781
+ invariant(
782
+ false,
783
+ 'Element type is invalid. Received a promise that resolves to: %s. ' +
784
+ 'Promise elements must resolve to a class or function.',
785
+ Component,
786
+ );
787
}
797
- return child;
788
+ }
789
+ return child;
790
+}
791
+
792
+function mountIndeterminateComponent(
793
+ _current,
794
+ workInProgress,
795
+ Component,
796
+ renderExpirationTime,
797
+) {
798
+ if (_current !== null) {
799
+ // An indeterminate component only mounts if it suspended inside a non-
800
+ // concurrent tree, in an inconsistent state. We want to tree it like
801
+ // a new mount, even though an empty version of it already committed.
802
+ // Disconnect the alternate pointers.
803
+ _current.alternate = null;
804
+ workInProgress.alternate = null;
805
+ // Since this is conceptually a new fiber, schedule a Placement effect
806
+ workInProgress.effectTag |= Placement;
807
}
808
809
+ const props = workInProgress.pendingProps;
810
const unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
811
const context = getMaskedContext(workInProgress, unmaskedContext);
812
1413
}
1414
break;
1415
}
1406
- case ClassComponentLazy: {
1407
- const thenable = workInProgress.type;
1408
- const Component = getResultFromResolvedLazyComponent(thenable);
1409
- if (isLegacyContextProvider(Component)) {
1410
- pushLegacyContextProvider(workInProgress);
1411
- }
1412
- break;
1413
- }
1416
case HostPortal:
1417
pushHostContainer(
1418
workInProgress,
1462
1463
switch (workInProgress.tag) {
1464
case IndeterminateComponent: {
1463
- const Component = workInProgress.type;
1465
+ const elementType = workInProgress.elementType;
1466
return mountIndeterminateComponent(
1467
current,
1468
workInProgress,
1467
- Component,
1468
- updateExpirationTime,
1469
+ elementType,
1470
renderExpirationTime,
1471
);
1472
}
1472
- case FunctionComponent: {
1473
- const Component = workInProgress.type;
1474
- const unresolvedProps = workInProgress.pendingProps;
1475
- return updateFunctionComponent(
1473
+ case LazyComponent: {
1474
+ const elementType = workInProgress.elementType;
1475
+ return mountLazyComponent(
1476
current,
1477
workInProgress,
1478
- Component,
1479
- unresolvedProps,
1478
+ elementType,
1479
+ updateExpirationTime,
1480
renderExpirationTime,
1481
);
1482
}
1483
- case FunctionComponentLazy: {
1484
- const thenable = workInProgress.type;
1485
- const Component = getResultFromResolvedLazyComponent(thenable);
1483
+ case FunctionComponent: {
1484
+ const Component = workInProgress.type;
1485
const unresolvedProps = workInProgress.pendingProps;
1487
- const child = updateFunctionComponent(
1486
+ const resolvedProps =
1487
+ workInProgress.elementType === Component
1488
+ ? unresolvedProps
1489
+ : resolveDefaultProps(Component, unresolvedProps);
1490
+ return updateFunctionComponent(
1491
current,
1492
workInProgress,
1493
Component,
1491
- resolveDefaultProps(Component, unresolvedProps),
1494
+ resolvedProps,
1495
renderExpirationTime,
1496
);
1494
- return child;
1497
}
1498
case ClassComponent: {
1499
const Component = workInProgress.type;
1500
const unresolvedProps = workInProgress.pendingProps;
1501
+ const resolvedProps =
1502
+ workInProgress.elementType === Component
1503
+ ? unresolvedProps
1504
+ : resolveDefaultProps(Component, unresolvedProps);
1505
return updateClassComponent(
1506
current,
1507
workInProgress,
1508
Component,
1503
- unresolvedProps,
1504
- renderExpirationTime,
1505
- );
1506
- }
1507
- case ClassComponentLazy: {
1508
- const thenable = workInProgress.type;
1509
- const Component = getResultFromResolvedLazyComponent(thenable);
1510
- const unresolvedProps = workInProgress.pendingProps;
1511
- const child = updateClassComponent(
1512
- current,
1513
- workInProgress,
1514
- Component,
1515
- resolveDefaultProps(Component, unresolvedProps),
1509
+ resolvedProps,
1510
renderExpirationTime,
1511
);
1518
- return child;
1512
}
1513
case HostRoot:
1514
return updateHostRoot(current, workInProgress, renderExpirationTime);
1530
);
1531
case ForwardRef: {
1532
const type = workInProgress.type;
1533
+ const unresolvedProps = workInProgress.pendingProps;
1534
+ const resolvedProps =
1535
+ workInProgress.elementType === type
1536
+ ? unresolvedProps
1537
+ : resolveDefaultProps(type, unresolvedProps);
1538
return updateForwardRef(
1539
current,
1540
workInProgress,
1541
type,
1544
- workInProgress.pendingProps,
1542
+ resolvedProps,
1543
renderExpirationTime,
1544
);
1545
}
1548
- case ForwardRefLazy: {
1549
- const thenable = workInProgress.type;
1550
- const Component = getResultFromResolvedLazyComponent(thenable);
1551
- const unresolvedProps = workInProgress.pendingProps;
1552
- const child = updateForwardRef(
1553
- current,
1554
- workInProgress,
1555
- Component,
1556
- resolveDefaultProps(Component, unresolvedProps),
1557
- renderExpirationTime,
1558
- );
1559
- return child;
1560
- }
1546
case Fragment:
1547
return updateFragment(current, workInProgress, renderExpirationTime);
1548
case Mode:
1563
);
1564
case PureComponent: {
1565
const type = workInProgress.type;
1566
+ const unresolvedProps = workInProgress.pendingProps;
1567
+ const resolvedProps =
1568
+ workInProgress.elementType === type
1569
+ ? unresolvedProps
1570
+ : resolveDefaultProps(type, unresolvedProps);
1571
return updatePureComponent(
1572
current,
1573
workInProgress,
1574
type,
1585
- workInProgress.pendingProps,
1586
- updateExpirationTime,
1587
- renderExpirationTime,
1588
- );
1589
- }
1590
- case PureComponentLazy: {
1591
- const thenable = workInProgress.type;
1592
- const Component = getResultFromResolvedLazyComponent(thenable);
1593
- const unresolvedProps = workInProgress.pendingProps;
1594
- const child = updatePureComponent(
1595
- current,
1596
- workInProgress,
1597
- Component,
1598
- resolveDefaultProps(Component, unresolvedProps),
1575
+ resolvedProps,
1576
updateExpirationTime,
1577
renderExpirationTime,
1578
);
1602
- return child;
1579
}
1580
default:
1581
invariant(