diff --git a/React 的源码深入/React 的流程解析 - commit 阶段/React 的流程解析 - commit阶段.md b/React 的源码深入/React 的流程解析 - commit 阶段/React 的流程解析 - commit阶段.md index 1a80e6d..0d35527 100644 --- a/React 的源码深入/React 的流程解析 - commit 阶段/React 的流程解析 - commit阶段.md +++ b/React 的源码深入/React 的流程解析 - commit 阶段/React 的流程解析 - commit阶段.md @@ -161,8 +161,29 @@ do { 关于 commitLayoutEffects: [[React 的深入探索 - commitLayoutEffects]] -结束三个循环之后 commit 阶段并没有结束,还会进入接下来逻辑 +结束三个循环之后 commit 阶段并没有结束,还会进入接下来的逻辑 ```javascript - +var rootDidHavePassiveEffects = rootDoesHavePassiveEffects; + +if (rootDoesHavePassiveEffects) { + // 本次更新存在 useEffect + rootDoesHavePassiveEffects = false; + // 将 root 赋值给 rootWithPendingPassiveEffects,没错就是开头的循环 + rootWithPendingPassiveEffects = root; + pendingPassiveEffectsLanes = lanes; + pendingPassiveEffectsRenderPriority = renderPriorityLevel; +} else { + // 本次更新不存在 useEffect + nextEffect = firstEffect; + while (nextEffect !== null) { + var nextNextEffect = nextEffect.nextEffect; + // 循环设置为 null,目的是为了垃圾回收 + nextEffect.nextEffect = null; + if (nextEffect.effectTag & Deletion) { + detachFiberAfterEffects(nextEffect); + } + nextEffect = nextNextEffect; + } +} ``` \ No newline at end of file