Skip to content

Commit 1fe2def

Browse files
Brian Vaughnzhengjitf
Brian Vaughn
authored andcommitted
Don't inject timeline hooks unless React supports profiling (facebook#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.)
1 parent 4268962 commit 1fe2def

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/react-reconciler/src/ReactFiberDevToolsHook.new.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean {
7474
return true;
7575
}
7676
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+
8290
// We have successfully injected, so now it is safe to set up hooks.
8391
injectedHook = hook;
8492
} catch (err) {

packages/react-reconciler/src/ReactFiberDevToolsHook.old.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ export function injectInternals(internals: Object): boolean {
7474
return true;
7575
}
7676
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+
8290
// We have successfully injected, so now it is safe to set up hooks.
8391
injectedHook = hook;
8492
} catch (err) {

0 commit comments

Comments
 (0)