@samitouri / QOS-React-2 / commits / 367249c175

Don't drill into owners list if no owner metadata is available

Brian Vaughn committed Apr 11, 2019 at 14:00 UTC 367249c175ab6f333fdfa2caf74cf2cb2c34c5b5
5 files changed +58 -30
src/backend/renderer.js
+4 -1
@@ -639,12 +639,15 @@ export function attach(
639 idToTreeBaseDurationMap.set(id, fiber.treeBaseDuration);
640 }
641
642 + const hasOwnerMetadata = fiber.hasOwnProperty('_debugOwner');
643 +
644 if (isRoot) {
643 - const operation = new Uint32Array(4);
645 + const operation = new Uint32Array(5);
646 operation[0] = TREE_OPERATION_ADD;
647 operation[1] = id;
648 operation[2] = ElementTypeRoot;
649 operation[3] = isProfilingSupported ? 1 : 0;
650 + operation[4] = hasOwnerMetadata ? 1 : 0;
651 addOperation(operation);
652 } else {
653 const { displayName, key, type } = getDataForFiber(fiber);
src/bridge.js
+1 -1
@@ -51,7 +51,7 @@ export default class Bridge extends EventEmitter {
51 this._wall.send(
52 this._messageQueue[i],
53 this._messageQueue[i + 1],
54 - this._messageQueue[i + 2],
54 + this._messageQueue[i + 2]
55 );
56 }
57 this._messageQueue.length = 0;
src/devtools/store.js
+25 -5
@@ -48,6 +48,7 @@ type Config = {|
48 |};
49
50 export type Capabilities = {|
51 + hasOwnerMetadata: boolean,
52 supportsProfiling: boolean,
53 |};
54
@@ -60,6 +61,9 @@ export default class Store extends EventEmitter {
61
62 _captureScreenshots: boolean = false;
63
64 + // At least one of the injected renderers contains (DEV only) owner metadata.
65 + _hasOwnerMetadata: boolean = false;
66 +
67 // Map of ID to Element.
68 // Elements are mutable (for now) to avoid excessive cloning during tree updates.
69 _idToElement: Map<number, Element> = new Map();
@@ -174,6 +178,10 @@ export default class Store extends EventEmitter {
178 this.emit('captureScreenshots');
179 }
180
181 + get hasOwnerMetadata(): boolean {
182 + return this._hasOwnerMetadata;
183 + }
184 +
185 // Profiling data has been recorded for at least one root.
186 get hasProfilingData(): boolean {
187 return (
@@ -534,9 +542,15 @@ export default class Store extends EventEmitter {
542 const supportsProfiling = operations[i] > 0;
543 i++;
544
545 + const hasOwnerMetadata = operations[i] > 0;
546 + i++;
547 +
548 this._roots = this._roots.concat(id);
549 this._rootIDToRendererID.set(id, rendererID);
539 - this._rootIDToCapabilities.set(id, { supportsProfiling });
550 + this._rootIDToCapabilities.set(id, {
551 + hasOwnerMetadata,
552 + supportsProfiling,
553 + });
554
555 this._idToElement.set(id, {
556 children: [],
@@ -768,12 +782,18 @@ export default class Store extends EventEmitter {
782 this._revision++;
783
784 if (haveRootsChanged) {
785 + this._hasOwnerMetadata = false;
786 this._supportsProfiling = false;
772 - this._rootIDToCapabilities.forEach(({ supportsProfiling }) => {
773 - if (supportsProfiling) {
774 - this._supportsProfiling = true;
787 + this._rootIDToCapabilities.forEach(
788 + ({ hasOwnerMetadata, supportsProfiling }) => {
789 + if (hasOwnerMetadata) {
790 + this._hasOwnerMetadata = true;
791 + }
792 + if (supportsProfiling) {
793 + this._supportsProfiling = true;
794 + }
795 }
776 - });
796 + );
797
798 this.emit('roots');
799 }
src/devtools/views/Components/TreeContext.js
+27 -23
@@ -484,30 +484,34 @@ function reduceOwnersState(store: Store, state: State, action: Action): State {
484 }
485 break;
486 case 'SELECT_OWNER':
487 - ownerStackIndex = ownerStack.indexOf(payload);
488 -
489 - // Always force reset selection to be the top of the new owner tree.
490 - selectedElementIndex = 0;
491 - prevSelectedElementIndex = null;
492 -
493 - // If this owner is already in the current stack, just select it.
494 - // Otherwise, create a new stack.
495 - if (ownerStackIndex < 0) {
496 - // Add this new owner, and fill in the owners above it as well.
497 - ownerStack = [];
498 - let currentOwnerID = ((payload: any): number);
499 - while (currentOwnerID !== 0) {
500 - ownerStack.unshift(currentOwnerID);
501 - currentOwnerID = ((store.getElementByID(
502 - currentOwnerID
503 - ): any): Element).ownerID;
504 - }
505 - ownerStackIndex = ownerStack.length - 1;
487 + // If the Store doesn't have any owners metadata, don't drill into an empty stack.
488 + // This is a confusing user experience.
489 + if (store.hasOwnerMetadata) {
490 + ownerStackIndex = ownerStack.indexOf(payload);
491 +
492 + // Always force reset selection to be the top of the new owner tree.
493 + selectedElementIndex = 0;
494 + prevSelectedElementIndex = null;
495 +
496 + // If this owner is already in the current stack, just select it.
497 + // Otherwise, create a new stack.
498 + if (ownerStackIndex < 0) {
499 + // Add this new owner, and fill in the owners above it as well.
500 + ownerStack = [];
501 + let currentOwnerID = ((payload: any): number);
502 + while (currentOwnerID !== 0) {
503 + ownerStack.unshift(currentOwnerID);
504 + currentOwnerID = ((store.getElementByID(
505 + currentOwnerID
506 + ): any): Element).ownerID;
507 + }
508 + ownerStackIndex = ownerStack.length - 1;
509
507 - if (searchText !== '') {
508 - searchIndex = null;
509 - searchResults = [];
510 - searchText = '';
510 + if (searchText !== '') {
511 + searchIndex = null;
512 + searchResults = [];
513 + searchText = '';
514 + }
515 }
516 }
517 break;
src/devtools/views/Profiler/CommitTreeBuilder.js
+1
@@ -194,6 +194,7 @@ function updateTree(
194
195 if (type === ElementTypeRoot) {
196 i++; // supportsProfiling flag
197 + i++; // hasOwnerMetadata flag
198
199 if (__DEBUG__) {
200 debug('Add', `new root fiber ${id}`);