Add runtime type checks around module boundary code (#22748)
Brian Vaughn committed
Nov 12, 2021 at 10:03 UTC
cb11155c86e756838a97679fb04c3256de101943
1 file changed
+13
-5
packages/react-reconciler/src/SchedulingProfiler.js
+13
-5
@@ -18,6 +18,7 @@ import {
18
import ReactVersion from 'shared/ReactVersion';
19
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
20
import {SCHEDULING_PROFILER_VERSION} from 'react-devtools-timeline/src/constants';
21
+import isArray from 'shared/isArray';
22
23
import {
24
getLabelForLane as getLabelForLane_old,
@@ -105,11 +106,18 @@ function markInternalModuleRanges() {
106
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges === 'function'
107
) {
108
const ranges = __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges();
108
- for (let i = 0; i < ranges.length; i++) {
109
- const [startStackFrame, stopStackFrame] = ranges[i];
110
-
111
- markAndClear(`--react-internal-module-start-${startStackFrame}`);
112
- markAndClear(`--react-internal-module-stop-${stopStackFrame}`);
109
+ // This check would not be required,
110
+ // except that it's possible for things to override __REACT_DEVTOOLS_GLOBAL_HOOK__.
111
+ if (isArray(ranges)) {
112
+ for (let i = 0; i < ranges.length; i++) {
113
+ const range = ranges[i];
114
+ if (isArray(range) && range.length === 2) {
115
+ const [startStackFrame, stopStackFrame] = ranges[i];
116
+
117
+ markAndClear(`--react-internal-module-start-${startStackFrame}`);
118
+ markAndClear(`--react-internal-module-stop-${stopStackFrame}`);
119
+ }
120
+ }
121
}
122
}
123
}