Git Product home page Git Product logo

Comments (7)

7kms avatar 7kms commented on May 12, 2024 2

这里实际上是在讨论completeWork函数的返回值, 绝大多数情况都返回的null(即不会派生出子节点). 只有一种特殊情况涉及到SuspenseComponent 和 SuspenseListComponent组件, 它们是有返回值的. @creamidea 已经贴上了对应的源码.
v17.0.2中, 这些组件虽然在源码中体现了, 实际上是用不上的. 这个是v18的feature, 需要安装v18对应的版本才能体验.

SuspenseComponent有下级fallback组件需要渲染, 所以completeWork函数会返回自身, 最后退出completeUnitOfWork, 再次进入beginWork阶段去生成fallback组件对应的fiber节点

from react-illustration-series.

7kms avatar 7kms commented on May 12, 2024 1

completeUnitOfWork 阶段会有VDOM 的拼接操作

这个能帮忙具体定位一下代码吗?我在 completeUnitOfWork 里面没有找到。谢谢

@jacty 指的vdom拼接是否就是指代的SuspenseComponent fallback这种形式?

from react-illustration-series.

creamidea avatar creamidea commented on May 12, 2024

看源码,有以下几种情况

SuspenseComponent & DidCapture

https://github.com/facebook/react/blob/e0aa5e205feee53043ce1ae8726fe732866e6ea7/packages/react-reconciler/src/ReactFiberCompleteWork.new.js#L1094

SuspenseListComponent

https://github.com/facebook/react/blob/e0aa5e205feee53043ce1ae8726fe732866e6ea7/packages/react-reconciler/src/ReactFiberCompleteWork.new.js#L1308

https://github.com/facebook/react/blob/e0aa5e205feee53043ce1ae8726fe732866e6ea7/packages/react-reconciler/src/ReactFiberCompleteWork.new.js#L1435

from react-illustration-series.

DaphnisLi avatar DaphnisLi commented on May 12, 2024

谢谢大佬解答

from react-illustration-series.

jacty avatar jacty commented on May 12, 2024

深度优先:先找当前节点下是否有子节点,没有的话则查找当前节点的兄弟节点,再没有则返回父节点进行同样类型的查找。
completeUnitOfWork 阶段会有VDOM 的拼接操作,这个拼接会导致当前节点存在新增节点的情况,则需要去查找该新增节点上的一些信息,比如是否还有更深的子节点以及新增节点的属性等。

from react-illustration-series.

creamidea avatar creamidea commented on May 12, 2024

completeUnitOfWork 阶段会有VDOM 的拼接操作

这个能帮忙具体定位一下代码吗?我在 completeUnitOfWork 里面没有找到。谢谢

from react-illustration-series.

DaphnisLi avatar DaphnisLi commented on May 12, 2024

确实,通过源码看出来,目前 Suspense 会出现新增 fiber 节点的操作。感谢大佬们 🙏

from react-illustration-series.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.