From 4b67db996bcf9d7f9e37515eb03c28588beb6187 Mon Sep 17 00:00:00 2001 From: YuJian Date: Tue, 26 Apr 2022 17:12:42 +0800 Subject: [PATCH] vault backup: 2022-04-26 17:12:42 --- .../React 的流程解析 - commit阶段.md | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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