14
TREE_OPERATION_REMOVE,
15
TREE_OPERATION_REMOVE_ROOT,
16
TREE_OPERATION_REORDER_CHILDREN,
17
+ TREE_OPERATION_SET_SUBTREE_MODE,
18
TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS,
19
TREE_OPERATION_UPDATE_TREE_BASE_DURATION,
20
} from '../constants';
34
BRIDGE_PROTOCOL,
35
currentBridgeProtocol,
36
} from 'react-devtools-shared/src/bridge';
37
+import {StrictMode} from 'react-devtools-shared/src/types';
38
39
import type {Element} from './views/Components/types';
40
import type {ComponentFilter, ElementType} from '../types';
74
export type Capabilities = {|
75
hasOwnerMetadata: boolean,
76
supportsProfiling: boolean,
77
+ supportsStrictMode: boolean,
78
|};
79
80
/**
815
}
816
};
817
818
+ _recursivelyUpdateSubtree(
819
+ id: number,
820
+ callback: (element: Element) => void,
821
+ ): void {
822
+ const element = this._idToElement.get(id);
823
+ if (element) {
824
+ callback(element);
825
+
826
+ element.children.forEach(child =>
827
+ this._recursivelyUpdateSubtree(child, callback),
828
+ );
829
+ }
830
+ }
831
+
832
onBridgeNativeStyleEditorSupported = ({
833
isSupported,
834
validAttributes,
900
debug('Add', `new root node ${id}`);
901
}
902
903
+ const isStrictModeCompliant = operations[i] > 0;
904
+ i++;
905
+
906
const supportsProfiling = operations[i] > 0;
907
i++;
908
909
+ const supportsStrictMode = operations[i] > 0;
910
+ i++;
911
+
912
const hasOwnerMetadata = operations[i] > 0;
913
i++;
914
917
this._rootIDToCapabilities.set(id, {
918
hasOwnerMetadata,
919
supportsProfiling,
920
+ supportsStrictMode,
921
});
922
923
+ // Not all roots support StrictMode;
924
+ // don't flag a root as non-compliant unless it also supports StrictMode.
925
+ const isStrictModeNonCompliant =
926
+ !isStrictModeCompliant && supportsStrictMode;
927
+
928
this._idToElement.set(id, {
929
children: [],
930
depth: -1,
932
hocDisplayNames: null,
933
id,
934
isCollapsed: false, // Never collapse roots; it would hide the entire tree.
935
+ isStrictModeNonCompliant,
936
key: null,
937
ownerID: 0,
938
parentID: 0,
988
hocDisplayNames,
989
id,
990
isCollapsed: this._collapseNodesByDefault,
991
+ isStrictModeNonCompliant: parentElement.isStrictModeNonCompliant,
992
key,
993
ownerID,
963
- parentID: parentElement.id,
994
+ parentID,
995
type,
996
weight: 1,
997
};
1081
haveErrorsOrWarningsChanged = true;
1082
}
1083
}
1084
+
1085
break;
1086
}
1087
case TREE_OPERATION_REMOVE_ROOT: {
1156
}
1157
break;
1158
}
1159
+ case TREE_OPERATION_SET_SUBTREE_MODE: {
1160
+ const id = operations[i + 1];
1161
+ const mode = operations[i + 2];
1162
+
1163
+ i += 3;
1164
+
1165
+ // If elements have already been mounted in this subtree, update them.
1166
+ // (In practice, this likely only applies to the root element.)
1167
+ if (mode === StrictMode) {
1168
+ this._recursivelyUpdateSubtree(id, element => {
1169
+ element.isStrictModeNonCompliant = false;
1170
+ });
1171
+ }
1172
+
1173
+ if (__DEBUG__) {
1174
+ debug(
1175
+ 'Subtree mode',
1176
+ `Subtree with root ${id} set to mode ${mode}`,
1177
+ );
1178
+ }
1179
+ break;
1180
+ }
1181
case TREE_OPERATION_UPDATE_TREE_BASE_DURATION:
1182
// Base duration updates are only sent while profiling is in progress.
1183
// We can ignore them at this point.