7kms / react-illustration-series

图解react源码, 用大量配图的方式, 致力于将react原理表述清楚.
http://7km.top/
GNU Affero General Public License v3.0
7.5k stars 804 forks source link

subtreeFlags是怎么代替firstEffect, nextEffect的? #49

Open Empire-T9 opened 2 years ago

Empire-T9 commented 2 years ago

最新版react代码,用subtreeFlags是代替firstEffect, nextEffect,这部分不是双链表了吗?

creamidea commented 2 years ago

是的,目前了解到这种是为了新的 Suspense 特性做的改造,在 commit 阶段需要再次遍历整树。能够让下面的例子中 Component 在 loading 的时候也能过显示出来

<Suspense fallback="loading...">
  // LazyComponent 需要请求远程数据才能展示
  <LazyComponent />

  // Component 正常组件
  <Component />
</Suspense>