MCPcopy Create free account
hub / github.com/BetaSu/big-react / commitRoot

Function commitRoot

packages/react-reconciler/src/workLoop.ts:309–368  ·  view source on GitHub ↗
(root: FiberRootNode)

Source from the content-addressed store, hash-verified

307}
308
309function commitRoot(root: FiberRootNode) {
310 const finishedWork = root.finishedWork;
311
312 if (finishedWork === null) {
313 return;
314 }
315
316 if (__DEV__) {
317 console.warn('commit阶段开始', finishedWork);
318 }
319 const lane = root.finishedLane;
320
321 if (lane === NoLane && __DEV__) {
322 console.error('commit阶段finishedLane不应该是NoLane');
323 }
324
325 // 重置
326 root.finishedWork = null;
327 root.finishedLane = NoLane;
328
329 markRootFinished(root, lane);
330
331 if (
332 (finishedWork.flags & PassiveMask) !== NoFlags ||
333 (finishedWork.subtreeFlags & PassiveMask) !== NoFlags
334 ) {
335 if (!rootDoesHasPassiveEffects) {
336 rootDoesHasPassiveEffects = true;
337 // 调度副作用
338 scheduleCallback(NormalPriority, () => {
339 // 执行副作用
340 flushPassiveEffects(root.pendingPassiveEffects);
341 return;
342 });
343 }
344 }
345
346 // 判断是否存在3个子阶段需要执行的操作
347 // root flags root subtreeFlags
348 const subtreeHasEffect =
349 (finishedWork.subtreeFlags & (MutationMask | PassiveMask)) !== NoFlags;
350 const rootHasEffect =
351 (finishedWork.flags & (MutationMask | PassiveMask)) !== NoFlags;
352
353 if (subtreeHasEffect || rootHasEffect) {
354 // beforeMutation
355 // mutation Placement
356 commitMutationEffects(finishedWork, root);
357
358 root.current = finishedWork;
359
360 // 阶段3/3:Layout
361 commitLayoutEffects(finishedWork, root);
362 } else {
363 root.current = finishedWork;
364 }
365
366 rootDoesHasPassiveEffects = false;

Callers 2

performSyncWorkOnRootFunction · 0.85

Calls 3

markRootFinishedFunction · 0.90
flushPassiveEffectsFunction · 0.85
ensureRootIsScheduledFunction · 0.85

Tested by

no test coverage detected