1. 程式人生 > 其它 >初窺React-8(updateContainer方法-p3)

初窺React-8(updateContainer方法-p3)

performSyncWorkOnRoot(root);
function performSyncWorkOnRoot(root) {
    if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
      {
        throw Error( "Should not already be working." );
      }
    }

    flushPassiveEffects();
    var lanes;
    var exitStatus;

    
if (root === workInProgressRoot && includesSomeLane(root.expiredLanes, workInProgressRootRenderLanes)) { // There's a partial tree, and at least one of its lanes has expired. Finish // rendering it before rendering the rest of the expired work. lanes = workInProgressRootRenderLanes; exitStatus
= renderRootSync(root, lanes); if (includesSomeLane(workInProgressRootIncludedLanes, workInProgressRootUpdatedLanes)) { // The render included lanes that were updated during the render phase. // For example, when unhiding a hidden tree, we include all the lanes // that were previously skipped when the tree was hidden. That set of
// lanes is a superset of the lanes we started rendering with. // // Note that this only happens when part of the tree is rendered // concurrently. If the whole tree is rendered synchronously, then there // are no interleaved events. lanes = getNextLanes(root, lanes); exitStatus = renderRootSync(root, lanes); } } else { lanes = getNextLanes(root, NoLanes); exitStatus = renderRootSync(root, lanes); } if (root.tag !== LegacyRoot && exitStatus === RootErrored) { executionContext |= RetryAfterError; // If an error occurred during hydration, // discard server response and fall back to client side render. if (root.hydrate) { root.hydrate = false; clearContainer(root.containerInfo); } // If something threw an error, try rendering one more time. We'll render // synchronously to block concurrent data mutations, and we'll includes // all pending updates are included. If it still fails after the second // attempt, we'll give up and commit the resulting tree. lanes = getLanesToRetrySynchronouslyOnError(root); if (lanes !== NoLanes) { exitStatus = renderRootSync(root, lanes); } } if (exitStatus === RootFatalErrored) { var fatalError = workInProgressRootFatalError; prepareFreshStack(root, NoLanes); markRootSuspended$1(root, lanes); ensureRootIsScheduled(root, now()); throw fatalError; }
   //由於這個是sync的,所以不存在插隊直接commit
// We now have a consistent tree. Because this is a sync render, we // will commit it even if something suspended. var finishedWork = root.current.alternate; root.finishedWork = finishedWork; root.finishedLanes = lanes; commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next // pending level. ensureRootIsScheduled(root, now()); return null; }

上一節  下一節