MCPcopy
hub / github.com/facebook/react / scheduleUpdateOnFiber

Function scheduleUpdateOnFiber

packages/react-reconciler/src/ReactFiberWorkLoop.js:916–1042  ·  view source on GitHub ↗
(
  root: FiberRoot,
  fiber: Fiber,
  lane: Lane,
)

Source from the content-addressed store, hash-verified

914}
915
916export function scheduleUpdateOnFiber(
917 root: FiberRoot,
918 fiber: Fiber,
919 lane: Lane,
920) {
921 if (__DEV__) {
922 if (isRunningInsertionEffect) {
923 console.error('useInsertionEffect must not schedule updates.');
924 }
925 }
926
927 if (__DEV__) {
928 if (isFlushingPassiveEffects) {
929 didScheduleUpdateDuringPassiveEffects = true;
930 }
931 }
932
933 // Check if the work loop is currently suspended and waiting for data to
934 // finish loading.
935 if (
936 // Suspended render phase
937 (root === workInProgressRoot &&
938 (workInProgressSuspendedReason === SuspendedOnData ||
939 workInProgressSuspendedReason === SuspendedOnAction)) ||
940 // Suspended commit phase
941 root.cancelPendingCommit !== null
942 ) {
943 // The incoming update might unblock the current render. Interrupt the
944 // current attempt and restart from the top.
945 prepareFreshStack(root, NoLanes);
946 const didAttemptEntireTree = false;
947 markRootSuspended(
948 root,
949 workInProgressRootRenderLanes,
950 workInProgressDeferredLane,
951 didAttemptEntireTree,
952 );
953 }
954
955 // Mark that the root has a pending update.
956 markRootUpdated(root, lane);
957
958 if (
959 (executionContext & RenderContext) !== NoContext &&
960 root === workInProgressRoot
961 ) {
962 // This update was dispatched during the render phase. This is a mistake
963 // if the update originates from user space (with the exception of local
964 // hook updates, which are handled differently and don't reach this
965 // function), but there are some internal React features that use this as
966 // an implementation detail, like selective hydration.
967 warnAboutRenderPhaseUpdatesInDEV(fiber);
968
969 // Track lanes that were updated during the render phase
970 workInProgressRootRenderPhaseUpdatedLanes = mergeLanes(
971 workInProgressRootRenderPhaseUpdatedLanes,
972 lane,
973 );

Callers 14

switchFunction · 0.90
ReactFiberHooks.jsFile · 0.90
enqueueRenderPhaseUpdateFunction · 0.90
updateContainerImplFunction · 0.90
enqueueSetStateFunction · 0.90
enqueueReplaceStateFunction · 0.90

Calls 13

markRootSuspendedFunction · 0.90
markRootUpdatedFunction · 0.90
mergeLanesFunction · 0.90
addFiberToLanesMapFunction · 0.90
nowFunction · 0.90
addTransitionToLanesMapFunction · 0.90
ensureRootIsScheduledFunction · 0.90
prepareFreshStackFunction · 0.85
resetRenderTimerFunction · 0.85

Tested by

no test coverage detected