From 505c15c9ef40556b72ddf5cb3a78a6b2dc56908e Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 20 Jan 2022 11:11:26 -0500 Subject: [PATCH] Don't inject timeline hooks unless React supports profiling (#23151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.) --- .../src/ReactFiberDevToolsHook.new.js | 18 +++++++++++++----- .../src/ReactFiberDevToolsHook.old.js | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js index a05cc6933e53d..8c245e1efb32d 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js @@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean { return true; } try { - rendererID = hook.inject({ - ...internals, - getLaneLabelMap, - injectProfilingHooks, - }); + if (enableSchedulingProfiler) { + // Conditionally inject these hooks only if Timeline profiler is supported by this build. + // This gives DevTools a way to feature detect that isn't tied to version number + // (since profiling and timeline are controlled by different feature flags). + internals = { + ...internals, + getLaneLabelMap, + injectProfilingHooks, + }; + } + + rendererID = hook.inject(internals); + // We have successfully injected, so now it is safe to set up hooks. injectedHook = hook; } catch (err) { diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js index 982c46ba44f36..defaf397deb78 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js @@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean { return true; } try { - rendererID = hook.inject({ - ...internals, - getLaneLabelMap, - injectProfilingHooks, - }); + if (enableSchedulingProfiler) { + // Conditionally inject these hooks only if Timeline profiler is supported by this build. + // This gives DevTools a way to feature detect that isn't tied to version number + // (since profiling and timeline are controlled by different feature flags). + internals = { + ...internals, + getLaneLabelMap, + injectProfilingHooks, + }; + } + + rendererID = hook.inject(internals); + // We have successfully injected, so now it is safe to set up hooks. injectedHook = hook; } catch (err) {