Don't inject timeline hooks unless React supports profiling (#23151)
This gives DevTools a way to detect whether the current React renderer supports Timeline profiling. (Version alone isn't enough to detect this, neither is general profiling support– since these two are controlled by different feature flags.)
Brian Vaughn committed
Jan 20, 2022 at 11:11 UTC
505c15c9ef40556b72ddf5cb3a78a6b2dc56908e
2 files changed
+26
-10
packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
+13
-5
@@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean {
74
return true;
75
}
76
try {
77
- rendererID = hook.inject({
78
- ...internals,
79
- getLaneLabelMap,
80
- injectProfilingHooks,
81
- });
77
+ if (enableSchedulingProfiler) {
78
+ // Conditionally inject these hooks only if Timeline profiler is supported by this build.
79
+ // This gives DevTools a way to feature detect that isn't tied to version number
80
+ // (since profiling and timeline are controlled by different feature flags).
81
+ internals = {
82
+ ...internals,
83
+ getLaneLabelMap,
84
+ injectProfilingHooks,
85
+ };
86
+ }
87
+
88
+ rendererID = hook.inject(internals);
89
+
90
// We have successfully injected, so now it is safe to set up hooks.
91
injectedHook = hook;
92
} catch (err) {
packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
+13
-5
@@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean {
74
return true;
75
}
76
try {
77
- rendererID = hook.inject({
78
- ...internals,
79
- getLaneLabelMap,
80
- injectProfilingHooks,
81
- });
77
+ if (enableSchedulingProfiler) {
78
+ // Conditionally inject these hooks only if Timeline profiler is supported by this build.
79
+ // This gives DevTools a way to feature detect that isn't tied to version number
80
+ // (since profiling and timeline are controlled by different feature flags).
81
+ internals = {
82
+ ...internals,
83
+ getLaneLabelMap,
84
+ injectProfilingHooks,
85
+ };
86
+ }
87
+
88
+ rendererID = hook.inject(internals);
89
+
90
// We have successfully injected, so now it is safe to set up hooks.
91
injectedHook = hook;
92
} catch (err) {