Skip to content

Commit

Permalink
Don't inject timeline hooks unless React supports profiling (facebook…
Browse files Browse the repository at this point in the history
…#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.)
  • Loading branch information
Brian Vaughn authored and nevilm-lt committed Apr 22, 2022
1 parent ef6b2f8 commit 27680a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 13 additions & 5 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 13 additions & 5 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 27680a1

Please sign in to comment.