Skip to content

Commit

Permalink
Assert that we always find a parent for DOM mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Nov 23, 2016
1 parent 718ed56 commit a1fadde
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function<T, P, I, TI, C>(
}
}

function getHostParent(fiber : Fiber) : null | I | C {
function getHostParent(fiber : Fiber) : I | C {
let parent = fiber.return;
while (parent) {
switch (parent.tag) {
Expand All @@ -79,7 +79,7 @@ module.exports = function<T, P, I, TI, C>(
}
parent = parent.return;
}
return null;
throw new Error('Expected to find a host parent.');
}

function isHostParent(fiber : Fiber) : boolean {
Expand Down Expand Up @@ -132,9 +132,6 @@ module.exports = function<T, P, I, TI, C>(
function commitInsertion(finishedWork : Fiber) : void {
// Recursively insert all host nodes into the parent.
const parent = getHostParent(finishedWork);
if (!parent) {
return;
}
const before = getHostSibling(finishedWork);
// We only have the top Fiber that was inserted but we need recurse down its
// children to find all the terminal nodes.
Expand Down Expand Up @@ -204,9 +201,7 @@ module.exports = function<T, P, I, TI, C>(
commitNestedUnmounts(node);
// After all the children have unmounted, it is now safe to remove the
// node from the tree.
if (parent) {
removeChild(parent, node.stateNode);
}
removeChild(parent, node.stateNode);
} else if (node.tag === Portal) {
// If this is a portal, then the parent is actually the portal itself.
// We need to keep track of which parent we're removing from.
Expand Down

0 comments on commit a1fadde

Please sign in to comment.