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

你是如何理解fiber的? #103

Open
Diamond2128 opened this issue Nov 7, 2022 · 1 comment
Open

你是如何理解fiber的? #103

Diamond2128 opened this issue Nov 7, 2022 · 1 comment

Comments

@Diamond2128
Copy link
Owner

https://segmentfault.com/a/1190000041094886

@Diamond2128
Copy link
Owner Author

Diamond2128 commented Nov 10, 2022

在React的concurrent模式下,低优先级任务执行过程中,一旦有更高优先级的任务进来,那么这个低优先级的任务会被取消,优先执行高优先级任务。等高优先级任务做完了,低优先级任务会被重新做一遍。

高优先级任务插队,低优先级任务重做的整个过程共有四个关键点:

ensureRootIsScheduled取消已有的低优先级更新任务,重新调度一个任务去做高优先级更新,并以root.pendingLanes中最重要的那部分lanes作为渲染优先级
执行更新任务时跳过updateQueue中的低优先级update,并将它的lane标记到fiber.lanes中。
fiber节点的complete阶段收集fiber.lanes到父级fiber的childLanes,一直到root。
commit阶段将所有root.childLanes连同root.lanes一并赋值给root.pendingLanes。
commit阶段的最后重新发起调度。

整个流程始终以高优先级任务为重,顾全大局,最能够体现React提升用户体验的决心。

https://juejin.cn/post/7089034676735574029

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

1 participant