Skip to content

Commit 351bf56

Browse files
sebmarkbageacusti
authored andcommitted
Assert that we always find a parent for DOM mutations
1 parent 0d26630 commit 351bf56

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/renderers/shared/fiber/ReactFiberCommitWork.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = function<T, P, I, TI, C>(
6666
}
6767
}
6868

69-
function getHostParent(fiber : Fiber) : null | I | C {
69+
function getHostParent(fiber : Fiber) : I | C {
7070
let parent = fiber.return;
7171
while (parent) {
7272
switch (parent.tag) {
@@ -79,7 +79,7 @@ module.exports = function<T, P, I, TI, C>(
7979
}
8080
parent = parent.return;
8181
}
82-
return null;
82+
throw new Error('Expected to find a host parent.');
8383
}
8484

8585
function isHostParent(fiber : Fiber) : boolean {
@@ -134,9 +134,6 @@ module.exports = function<T, P, I, TI, C>(
134134
function commitInsertion(finishedWork : Fiber) : void {
135135
// Recursively insert all host nodes into the parent.
136136
const parent = getHostParent(finishedWork);
137-
if (!parent) {
138-
return;
139-
}
140137
const before = getHostSibling(finishedWork);
141138
// We only have the top Fiber that was inserted but we need recurse down its
142139
// children to find all the terminal nodes.
@@ -208,9 +205,7 @@ module.exports = function<T, P, I, TI, C>(
208205
commitNestedUnmounts(node);
209206
// After all the children have unmounted, it is now safe to remove the
210207
// node from the tree.
211-
if (parent) {
212-
removeChild(parent, node.stateNode);
213-
}
208+
removeChild(parent, node.stateNode);
214209
} else if (node.tag === Portal) {
215210
// If this is a portal, then the parent is actually the portal itself.
216211
// We need to keep track of which parent we're removing from.

0 commit comments

Comments
 (0)