Skip to content

Why not use an array to save fibers with side effects, but use a linked list on the finishedWork tree #24770

Closed as not planned
@lizuncong

Description

@lizuncong

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.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions