@samitouri / QOS-React-2 / commits / ccecde76d1

Harden assertions

Dan Abramov committed Apr 19, 2019 at 00:29 UTC ccecde76d1ffc7beee5c3e80987990ea233b4ceb
2 files changed +23 -9
src/backend/renderer.js
+5 -8
@@ -239,15 +239,12 @@ export function attach(
239 parentFiber == null ? null : getDataForFiber(parentFiber);
240 const parentFiberDisplayName =
241 (parentFiberData && parentFiberData.displayName) || 'null';
242 + // NOTE: calling getFiberID or getPrimaryFiber is unsafe here
243 + // because it will put them in the map. For now, we'll omit them.
244 + // TODO: better debugging story for this.
245 console.log(
243 - `[renderer] %c${name} %c${getFiberID(
244 - getPrimaryFiber(fiber)
245 - )}:${fiberDisplayName} %c${
246 - parentFiber
247 - ? getFiberID(getPrimaryFiber(parentFiber)) +
248 - ':' +
249 - parentFiberDisplayName
250 - : ''
246 + `[renderer] %c${name} %c${fiberDisplayName} %c${
247 + parentFiber ? parentFiberDisplayName : ''
248 }`,
249 'color: red; font-weight: bold;',
250 'color: blue;',
src/devtools/store.js
+18 -1
@@ -711,9 +711,17 @@ export default class Store extends EventEmitter {
711
712 element = ((this._idToElement.get(id): any): Element);
713 parentID = element.parentID;
714 -
714 weightDelta = -element.weight;
715
716 + if (element.children.length > 0) {
717 + throw new Error(
718 + 'Fiber ' +
719 + id +
720 + ' was removed before its children. ' +
721 + 'This is a bug in React DevTools.'
722 + );
723 + }
724 +
725 this._idToElement.delete(id);
726
727 if (parentID === 0) {
@@ -769,7 +777,16 @@ export default class Store extends EventEmitter {
777 }
778
779 element = ((this._idToElement.get(id): any): Element);
780 + const prevChildren = element.children;
781 element.children = Array.from(children);
782 + if (element.children.length !== prevChildren.length) {
783 + throw new Error(
784 + 'Fiber ' +
785 + id +
786 + ' received a different number of children on reorder. ' +
787 + 'This is a bug in React DevTools.'
788 + );
789 + }
790
791 if (!element.isCollapsed) {
792 const prevWeight = element.weight;