just-react icon indicating copy to clipboard operation
just-react copied to clipboard

coomitRoot阶段layout阶段阐述存疑

Open daxiazilong opened this issue 3 years ago • 0 comments
trafficstars

beforeMutation阶段 就讲过,before mutation阶段在scheduleCallback中调度flushPassiveEffects

而在layout阶段

对于FunctionComponent及相关类型,他会调用useLayoutEffect hook的回调函数,调度useEffect的销毁与回调函数

光从以上两段论述中,是不是可以说 useEffect的相关回调在beforeMutation和layout两个阶段都被调用了啊

17.0.2源码我大概看了下 对应位置的代码似乎变成了:

case FunctionComponent:
    case ForwardRef:
    case SimpleMemoComponent:
    case Block:
      {
        // At this point layout effects have already been destroyed (during mutation phase).
        // This is done to prevent sibling component effects from interfering with each other,
        // e.g. a destroy function in one component should never override a ref set
        // by a create function in another component during the same commit.
        {
          commitHookEffectListMount(Layout | HasEffect, finishedWork);
        }

        schedulePassiveEffects(finishedWork);
        return;
      }

daxiazilong avatar Jan 21 '22 02:01 daxiazilong