Added a new invariant to the store (bridge operations handler)
Brian Vaughn committed
Apr 18, 2019 at 15:40 UTC
3dfbf8ad6bd85e85c131009bd4f6a6652e8fcf7b
1 file changed
+25
-20
src/devtools/store.js
+25
-20
@@ -597,16 +597,14 @@ export default class Store extends EventEmitter {
597
i = i + 3;
598
599
if (this._idToElement.has(id)) {
600
- throw new Error(
601
- 'Store already contains fiber ' +
602
- id +
603
- '. This is a bug in React DevTools.'
600
+ throw Error(
601
+ `Cannot add node ${id} because a node with that id is already in the Store.`
602
);
603
}
604
605
if (type === ElementTypeRoot) {
606
if (__DEBUG__) {
609
- debug('Add', `new root fiber ${id}`);
607
+ debug('Add', `new root node ${id}`);
608
}
609
610
const supportsProfiling = operations[i] > 0;
@@ -664,7 +662,13 @@ export default class Store extends EventEmitter {
662
if (__DEBUG__) {
663
debug(
664
'Add',
667
- `fiber ${id} (${displayName || 'null'}) as child of ${parentID}`
665
+ `node ${id} (${displayName || 'null'}) as child of ${parentID}`
666
+ );
667
+ }
668
+
669
+ if (!this._idToElement.has(parentID)) {
670
+ throw Error(
671
+ `Cannot add child ${id} to parent ${parentID} because parent node was not found in the Store.`
672
);
673
}
674
@@ -698,10 +702,8 @@ export default class Store extends EventEmitter {
702
id = ((operations[i + 1]: any): number);
703
704
if (!this._idToElement.has(id)) {
701
- throw new Error(
702
- 'Store does not contain fiber ' +
703
- id +
704
- '. This is a bug in React DevTools.'
705
+ throw Error(
706
+ `Cannot remove node ${id} because no matching node was found in the Store.`
707
);
708
}
709
@@ -716,7 +718,7 @@ export default class Store extends EventEmitter {
718
719
if (parentID === 0) {
720
if (__DEBUG__) {
719
- debug('Remove', `fiber ${id} root`);
721
+ debug('Remove', `node ${id} root`);
722
}
723
724
this._roots = this._roots.filter(rootID => rootID !== id);
@@ -726,15 +728,12 @@ export default class Store extends EventEmitter {
728
haveRootsChanged = true;
729
} else {
730
if (__DEBUG__) {
729
- debug('Remove', `fiber ${id} from parent ${parentID}`);
731
+ debug('Remove', `node ${id} from parent ${parentID}`);
732
}
733
parentElement = ((this._idToElement.get(parentID): any): Element);
734
if (parentElement === undefined) {
733
- throw new Error(
734
- 'Fiber ' +
735
- id +
736
- ' was removed after its parent. ' +
737
- 'This is a bug in React DevTools.'
735
+ throw Error(
736
+ `Cannot remove node ${id} from parent ${parentID} because no matching node was found in the Store.`
737
);
738
}
739
parentElement.children = parentElement.children.filter(
@@ -760,7 +759,13 @@ export default class Store extends EventEmitter {
759
i = i + 3 + numChildren;
760
761
if (__DEBUG__) {
763
- debug('Re-order', `fiber ${id} children ${children.join(',')}`);
762
+ debug('Re-order', `Node ${id} children ${children.join(',')}`);
763
+ }
764
+
765
+ if (!this._idToElement.has(id)) {
766
+ throw Error(
767
+ `Cannot reorder children for node ${id} because no matching node was found in the Store.`
768
+ );
769
}
770
771
element = ((this._idToElement.get(id): any): Element);
@@ -898,7 +903,7 @@ export default class Store extends EventEmitter {
903
const element = ((this.getElementAtIndex(i): any): Element);
904
905
if (element == null) {
901
- throw Error(`No element for index ${i}`);
906
+ throw Error(`Could not find element at index ${i}`);
907
}
908
909
let prefix = ' ';
@@ -928,7 +933,7 @@ export default class Store extends EventEmitter {
933
// Make sure the pretty-printed test align with the Store's reported number of total rows.
934
if (rootWeight !== this._weightAcrossRoots) {
935
throw Error(
931
- `Inconsistent store state. Individual root weights (${rootWeight}) do not match total weight (${
936
+ `Inconsistent Store state. Individual root weights (${rootWeight}) do not match total weight (${
937
this._weightAcrossRoots
938
})`
939
);