Assert removal happens in the right order

This commit is contained in:
Dan Abramov
2019-04-18 16:02:08 +01:00
parent 0d932d770b
commit d02d93712e
2 changed files with 14 additions and 7 deletions
+4 -4
View File
@@ -752,13 +752,13 @@ export function attach(
nextOperation[1] = id;
endNextOperation(false);
} else if (!shouldFilterFiber(fiber)) {
// Non-root fibers are deleted during the commit phase.
// They are deleted in the child-first order. However
// DevTools currently expects deletions to be parent-first.
// This is why we unshift deletions rather tha
beginNextOperation(2);
nextOperation[0] = TREE_OPERATION_REMOVE;
nextOperation[1] = id;
// Non-root fibers are deleted during the commit phase.
// They are deleted in the parent-first order. However
// DevTools currently expects deletions to be child-first.
// This is why we prepend the delete operation to the queue.
endNextOperation(true);
}
fiberToIDMap.delete(primaryFiber);
+10 -3
View File
@@ -760,8 +760,7 @@ export default class Store extends EventEmitter {
this._idToElement.delete(id);
parentElement = ((this._idToElement.get(parentID): any): Element);
if (parentElement == null) {
if (parentID === 0) {
if (__DEBUG__) {
debug('Remove', `fiber ${id} root`);
}
@@ -775,7 +774,15 @@ export default class Store extends EventEmitter {
if (__DEBUG__) {
debug('Remove', `fiber ${id} from parent ${parentID}`);
}
parentElement = ((this._idToElement.get(parentID): any): Element);
if (parentElement === undefined) {
throw new Error(
'Fiber ' +
id +
' was removed after its parent. ' +
'This is a bug in React DevTools.'
);
}
parentElement.children = parentElement.children.filter(
childID => childID !== id
);