Assert removal happens in the right order
Dan Abramov committed
Apr 18, 2019 at 16:02 UTC
d02d93712ed6a5eda885ceb5116cdc9192b478f2
2 files changed
+14
-7
src/backend/renderer.js
+4
-4
@@ -752,13 +752,13 @@ export function attach(
752
nextOperation[1] = id;
753
endNextOperation(false);
754
} else if (!shouldFilterFiber(fiber)) {
755
- // Non-root fibers are deleted during the commit phase.
756
- // They are deleted in the child-first order. However
757
- // DevTools currently expects deletions to be parent-first.
758
- // This is why we unshift deletions rather tha
755
beginNextOperation(2);
756
nextOperation[0] = TREE_OPERATION_REMOVE;
757
nextOperation[1] = id;
758
+ // Non-root fibers are deleted during the commit phase.
759
+ // They are deleted in the parent-first order. However
760
+ // DevTools currently expects deletions to be child-first.
761
+ // This is why we prepend the delete operation to the queue.
762
endNextOperation(true);
763
}
764
fiberToIDMap.delete(primaryFiber);
src/devtools/store.js
+10
-3
@@ -760,8 +760,7 @@ export default class Store extends EventEmitter {
760
761
this._idToElement.delete(id);
762
763
- parentElement = ((this._idToElement.get(parentID): any): Element);
764
- if (parentElement == null) {
763
+ if (parentID === 0) {
764
if (__DEBUG__) {
765
debug('Remove', `fiber ${id} root`);
766
}
@@ -775,7 +774,15 @@ export default class Store extends EventEmitter {
774
if (__DEBUG__) {
775
debug('Remove', `fiber ${id} from parent ${parentID}`);
776
}
778
-
777
+ parentElement = ((this._idToElement.get(parentID): any): Element);
778
+ if (parentElement === undefined) {
779
+ throw new Error(
780
+ 'Fiber ' +
781
+ id +
782
+ ' was removed after its parent. ' +
783
+ 'This is a bug in React DevTools.'
784
+ );
785
+ }
786
parentElement.children = parentElement.children.filter(
787
childID => childID !== id
788
);