Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lizuncong opened this issue Jun 22, 2022 · 3 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@lizuncong
Copy link

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.
}
@F3n67u
Copy link

F3n67u commented Jun 22, 2022

FWIW, This code is removed during the refactor of the effect list implement, see this pr: #20644

Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

2 participants