( current: Fiber | null, workInProgress: Fiber, Component: any, nextProps: any, renderLanes: Lanes, )
| 1575 | } |
| 1576 | |
| 1577 | function updateClassComponent( |
| 1578 | current: Fiber | null, |
| 1579 | workInProgress: Fiber, |
| 1580 | Component: any, |
| 1581 | nextProps: any, |
| 1582 | renderLanes: Lanes, |
| 1583 | ) { |
| 1584 | if (__DEV__) { |
| 1585 | // This is used by DevTools to force a boundary to error. |
| 1586 | switch (shouldError(workInProgress)) { |
| 1587 | case false: { |
| 1588 | const instance = workInProgress.stateNode; |
| 1589 | const ctor = workInProgress.type; |
| 1590 | // TODO This way of resetting the error boundary state is a hack. |
| 1591 | // Is there a better way to do this? |
| 1592 | const tempInstance = new ctor( |
| 1593 | workInProgress.memoizedProps, |
| 1594 | instance.context, |
| 1595 | ); |
| 1596 | const state = tempInstance.state; |
| 1597 | instance.updater.enqueueSetState(instance, state, null); |
| 1598 | break; |
| 1599 | } |
| 1600 | case true: { |
| 1601 | workInProgress.flags |= DidCapture; |
| 1602 | workInProgress.flags |= ShouldCapture; |
| 1603 | // eslint-disable-next-line react-internal/prod-error-codes |
| 1604 | const error = new Error('Simulated error coming from DevTools'); |
| 1605 | const lane = pickArbitraryLane(renderLanes); |
| 1606 | workInProgress.lanes = mergeLanes(workInProgress.lanes, lane); |
| 1607 | // Schedule the error boundary to re-render using updated state |
| 1608 | const root: FiberRoot | null = getWorkInProgressRoot(); |
| 1609 | if (root === null) { |
| 1610 | throw new Error( |
| 1611 | 'Expected a work-in-progress root. This is a bug in React. Please file an issue.', |
| 1612 | ); |
| 1613 | } |
| 1614 | const update = createClassErrorUpdate(lane); |
| 1615 | initializeClassErrorUpdate( |
| 1616 | update, |
| 1617 | root, |
| 1618 | workInProgress, |
| 1619 | createCapturedValueAtFiber(error, workInProgress), |
| 1620 | ); |
| 1621 | enqueueCapturedUpdate(workInProgress, update); |
| 1622 | break; |
| 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | // Push context providers early to prevent context stack mismatches. |
| 1628 | // During mounting we don't know the child context yet as the instance doesn't exist. |
| 1629 | // We will invalidate the child context in finishClassComponent() right after rendering. |
| 1630 | let hasContext; |
| 1631 | if (isLegacyContextProvider(Component)) { |
| 1632 | hasContext = true; |
| 1633 | pushLegacyContextProvider(workInProgress); |
| 1634 | } else { |
no test coverage detected