Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completeUnitOfWork 中 if 条件的含义 #70

Open
DaphnisLi opened this issue Mar 8, 2022 · 7 comments
Open

completeUnitOfWork 中 if 条件的含义 #70

DaphnisLi opened this issue Mar 8, 2022 · 7 comments

Comments

@DaphnisLi
Copy link

这里的 if 条件含义是什么?

image

@jacty
Copy link
Contributor

jacty commented Mar 10, 2022

当 completedWork.flags 的值表示还有“副作用”存在的话进入下一个循环查找该“副作用”存在于哪个Fiber 上并进行相应的增删改查处理。

@7kms
Copy link
Owner

7kms commented Mar 11, 2022

这里确切来讲是异常判断, completeUnitOfWork正常来讲就是深度优先遍历的回溯阶段会调用.
特殊情况就是在beginWork阶段发生异常, 也会调用, 这时候completeWork.flags中会包含Incomplete. 所以这里有个if判断, 不同情况下的处理不一样.

可以对照一下源码中的英文注释

https://github.com/facebook/react/blob/v17.0.2/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L1682

@DaphnisLi
Copy link
Author

这里确切来讲是异常判断, completeUnitOfWork正常来讲就是深度优先遍历的回溯阶段会调用. 特殊情况就是在beginWork阶段发生异常, 也会调用, 这时候completeWork.flags中会包含Incomplete. 所以这里有个if判断, 不同情况下的处理不一样.

可以对照一下源码中的英文注释

https://github.com/facebook/react/blob/v17.0.2/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L1682

beginWork 阶段的异常情况指的是 “并没有把该 fiber 节点的所有副作用都设置到 fiber.flags 上” ?

@7kms
Copy link
Owner

7kms commented Mar 11, 2022

异常就是指出现了代码运行时错误, 会设置completeWork.flags |= Incomplete

@DaphnisLi
Copy link
Author

异常就是指出现了代码运行时错误, 会设置completeWork.flags |= Incomplete

根本原因还是 报错影响了 fiber 树的构建吧?

@7kms
Copy link
Owner

7kms commented Mar 29, 2022

异常就是指出现了代码运行时错误, 会设置completeWork.flags |= Incomplete

根本原因还是 报错影响了 fiber 树的构建吧?

是的呀

@creamidea
Copy link

Incomplete 目前看有 2 个情况会使用到:一个 ErrorBoundary,另一个 Suspense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants