( root: FiberRootNode, didTimeout: boolean )
| 170 | } |
| 171 | |
| 172 | function performConcurrentWorkOnRoot( |
| 173 | root: FiberRootNode, |
| 174 | didTimeout: boolean |
| 175 | ): any { |
| 176 | // 保证useEffect回调执行 |
| 177 | const curCallback = root.callbackNode; |
| 178 | const didFlushPassiveEffect = flushPassiveEffects(root.pendingPassiveEffects); |
| 179 | if (didFlushPassiveEffect) { |
| 180 | if (root.callbackNode !== curCallback) { |
| 181 | return null; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | const lane = getNextLane(root); |
| 186 | const curCallbackNode = root.callbackNode; |
| 187 | if (lane === NoLane) { |
| 188 | return null; |
| 189 | } |
| 190 | const needSync = lane === SyncLane || didTimeout; |
| 191 | // render阶段 |
| 192 | const exitStatus = renderRoot(root, lane, !needSync); |
| 193 | |
| 194 | switch (exitStatus) { |
| 195 | // 中断 |
| 196 | case RootInComplete: |
| 197 | if (root.callbackNode !== curCallbackNode) { |
| 198 | return null; |
| 199 | } |
| 200 | return performConcurrentWorkOnRoot.bind(null, root); |
| 201 | case RootCompleted: |
| 202 | const finishedWork = root.current.alternate; |
| 203 | root.finishedWork = finishedWork; |
| 204 | root.finishedLane = lane; |
| 205 | wipRootRenderLane = NoLane; |
| 206 | commitRoot(root); |
| 207 | break; |
| 208 | case RootDidNotComplete: |
| 209 | markRootSuspended(root, lane); |
| 210 | wipRootRenderLane = NoLane; |
| 211 | ensureRootIsScheduled(root); |
| 212 | break; |
| 213 | default: |
| 214 | if (__DEV__) { |
| 215 | console.error('还未实现的并发更新结束状态'); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | function performSyncWorkOnRoot(root: FiberRootNode) { |
| 221 | const nextLane = getNextLane(root); |
nothing calls this directly
no test coverage detected