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

commitWork function should return after commitDeletion(anOldFiber, domParent) #44

Open
1adybug opened this issue Aug 25, 2022 · 0 comments

Comments

@1adybug
Copy link

1adybug commented Aug 25, 2022

function commitWork(fiber) {
  if (!fiber) {
    return
  }

  let domParentFiber = fiber.parent
  while (!domParentFiber.dom) {
    domParentFiber = domParentFiber.parent
  }
  const domParent = domParentFiber.dom

  if (
    fiber.effectTag === "PLACEMENT" &&
    fiber.dom != null
  ) {
    domParent.appendChild(fiber.dom)
  } else if (
    fiber.effectTag === "UPDATE" &&
    fiber.dom != null
  ) {
    updateDom(
      fiber.dom,
      fiber.alternate.props,
      fiber.props
    )
  } else if (fiber.effectTag === "DELETION") {
    commitDeletion(fiber, domParent)

    // function should return at this moment
    return
  }

  commitWork(fiber.child)
  commitWork(fiber.sibling)
}

let's call the fiber to be deleted oldFiber

if commitWork function didnt return after commitDeletion(oldFiber, domParent), it will commitWork(oldFiber.child) and commitWork(oldFiber.sibling).

This may cause a terrible bug, because u dont know what type is oldFiber.child.effectTag or oldFiber.sibiling.effectTag

and commitWork function dont know the two fibers are old fibers and will treat them as current fiber to process.

@1adybug 1adybug changed the title function should return after commitDeletion(anOldFiber, domParent) commitWork function should return after commitDeletion(anOldFiber, domParent) Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant