@samitouri / QOS-React / commits / fde18a4562

Assert that we always find a parent for DOM mutations

Sebastian Markbage committed Nov 23, 2016 at 15:29 UTC fde18a4562f0cfe5dce3afce44579616d09d079a
1 file changed +3 -8
src/renderers/shared/fiber/ReactFiberCommitWork.js
+3 -8
@@ -66,7 +66,7 @@ module.exports = function<T, P, I, TI, C>(
66 }
67 }
68
69 - function getHostParent(fiber : Fiber) : null | I | C {
69 + function getHostParent(fiber : Fiber) : I | C {
70 let parent = fiber.return;
71 while (parent) {
72 switch (parent.tag) {
@@ -79,7 +79,7 @@ module.exports = function<T, P, I, TI, C>(
79 }
80 parent = parent.return;
81 }
82 - return null;
82 + throw new Error('Expected to find a host parent.');
83 }
84
85 function isHostParent(fiber : Fiber) : boolean {
@@ -134,9 +134,6 @@ module.exports = function<T, P, I, TI, C>(
134 function commitInsertion(finishedWork : Fiber) : void {
135 // Recursively insert all host nodes into the parent.
136 const parent = getHostParent(finishedWork);
137 - if (!parent) {
138 - return;
139 - }
137 const before = getHostSibling(finishedWork);
138 // We only have the top Fiber that was inserted but we need recurse down its
139 // children to find all the terminal nodes.
@@ -208,9 +205,7 @@ module.exports = function<T, P, I, TI, C>(
205 commitNestedUnmounts(node);
206 // After all the children have unmounted, it is now safe to remove the
207 // node from the tree.
211 - if (parent) {
212 - removeChild(parent, node.stateNode);
213 - }
208 + removeChild(parent, node.stateNode);
209 } else if (node.tag === Portal) {
210 // If this is a portal, then the parent is actually the portal itself.
211 // We need to keep track of which parent we're removing from.