Closed as not planned
Closed as not planned
Description
Hello,i'm curious why React17 uses a linked list on finishedWork tree instead of using an array to hold fiber nodes with side effects. It seems that it is easier to understand with arrays. Thank you for your answer
let effectFiberList = []; // an array to hold fiber nodes with side effects
// in the deleteChild function, we can add the childToDelete directly to the effectFiberList
function ChildReconciler(shouldTrackSideEffects) {
function deleteChild(returnFiber, childToDelete) {
if (!shouldTrackSideEffects) {
// Noop.
return;
}
// var last = returnFiber.lastEffect;
// if (last !== null) {
// last.nextEffect = childToDelete;
// returnFiber.lastEffect = childToDelete;
// } else {
// returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
// }
effectFiberList.push(childToDelete);
// childToDelete.nextEffect = null;
childToDelete.flags = Deletion;
}
}
// and in the completeUnitOfWork
function completeUnitOfWork(unitOfWork) {
var completedWork = unitOfWork;
do {
// ....
var flags = completedWork.flags;
if (flags > PerformedWork) {
// if (returnFiber.lastEffect !== null) {
// returnFiber.lastEffect.nextEffect = completedWork;
// } else {
// returnFiber.firstEffect = completedWork;
// }
// returnFiber.lastEffect = completedWork;
effectFiberList.push(completedWork);
}
//....
completedWork = returnFiber; // Update the next thing we're working on in case something throws.
workInProgress = completedWork;
} while (completedWork !== null); // We've reached the root.
}