如题,比如 ReactFilberScheduler.js 中有一个全局变量 isRendering 变量在 requestWork 和 performWorkOnRoot 方法中有用到,
requestWork 函数开头判断当 isRendering = true 的直接返回return;而在 performWorkOnRoot 的开头将 isRendering 置为 true 而在末尾置为 false,那么问题来了 requestWork 的开头对 isRendering 的判断有什么意义?
function requestWork(root: FiberRoot, expirationTime: ExpirationTime) {
addRootToSchedule(root, expirationTime);
if (isRendering) {
// Prevent reentrancy. Remaining work will be scheduled at the end of
// the currently rendering batch.
return;
}
//....Omitted code
}
function performWorkOnRoot(root: FiberRoot, expirationTime: ExpirationTime, isExpired: boolean) {
invariant(
!isRendering,
'performWorkOnRoot was called recursively. This error is likely caused ' +
'by a bug in React. Please file an issue.',
);
isRendering = true;
//...Omitted code
isRendering = false;
}
pardon110
相关分类