Skip to content

Commit bdd6e96

Browse files
committed
Assert that we always find a parent for DOM mutations
1 parent e830a49 commit bdd6e96

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 {
@@ -132,9 +132,6 @@ module.exports = function<T, P, I, TI, C>(
132132
function commitInsertion(finishedWork : Fiber) : void {
133133
// Recursively insert all host nodes into the parent.
134134
const parent = getHostParent(finishedWork);
135-
if (!parent) {
136-
return;
137-
}
138135
const before = getHostSibling(finishedWork);
139136
// We only have the top Fiber that was inserted but we need recurse down its
140137
// children to find all the terminal nodes.
@@ -204,9 +201,7 @@ module.exports = function<T, P, I, TI, C>(
204201
commitNestedUnmounts(node);
205202
// After all the children have unmounted, it is now safe to remove the
206203
// node from the tree.
207-
if (parent) {
208-
removeChild(parent, node.stateNode);
209-
}
204+
removeChild(parent, node.stateNode);
210205
} else if (node.tag === Portal) {
211206
// If this is a portal, then the parent is actually the portal itself.
212207
// We need to keep track of which parent we're removing from.

0 commit comments

Comments
 (0)