diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.js index f7bebce841d5b..a92c8032f678f 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.js @@ -7,8 +7,13 @@ * @flow */ +import {enableProfilerTimer} from 'shared/ReactFeatureFlags'; +import {requestCurrentTime} from './ReactFiberScheduler'; +import {inferPriorityFromExpirationTime} from './ReactFiberExpirationTime'; + import type {Fiber} from './ReactFiber'; import type {FiberRoot} from './ReactFiberRoot'; +import type {ExpirationTime} from './ReactFiberExpirationTime'; import warningWithoutStack from 'shared/warningWithoutStack'; @@ -18,23 +23,6 @@ let onCommitFiberRoot = null; let onCommitFiberUnmount = null; let hasLoggedError = false; -function catchErrors(fn) { - return function(arg) { - try { - return fn(arg); - } catch (err) { - if (__DEV__ && !hasLoggedError) { - hasLoggedError = true; - warningWithoutStack( - false, - 'React DevTools encountered an error: %s', - err, - ); - } - } - }; -} - export const isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined'; @@ -65,12 +53,43 @@ export function injectInternals(internals: Object): boolean { try { const rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks. - onCommitFiberRoot = catchErrors(root => - hook.onCommitFiberRoot(rendererID, root), - ); - onCommitFiberUnmount = catchErrors(fiber => - hook.onCommitFiberUnmount(rendererID, fiber), - ); + onCommitFiberRoot = (root, expirationTime) => { + try { + if (enableProfilerTimer) { + const currentTime = requestCurrentTime(); + const priorityLevel = inferPriorityFromExpirationTime( + currentTime, + expirationTime, + ); + hook.onCommitFiberRoot(rendererID, root, priorityLevel); + } else { + hook.onCommitFiberRoot(rendererID, root); + } + } catch (err) { + if (__DEV__ && !hasLoggedError) { + hasLoggedError = true; + warningWithoutStack( + false, + 'React DevTools encountered an error: %s', + err, + ); + } + } + }; + onCommitFiberUnmount = fiber => { + try { + hook.onCommitFiberUnmount(rendererID, fiber); + } catch (err) { + if (__DEV__ && !hasLoggedError) { + hasLoggedError = true; + warningWithoutStack( + false, + 'React DevTools encountered an error: %s', + err, + ); + } + } + }; } catch (err) { // Catch all errors because it is unsafe to throw during initialization. if (__DEV__) { @@ -85,9 +104,9 @@ export function injectInternals(internals: Object): boolean { return true; } -export function onCommitRoot(root: FiberRoot) { +export function onCommitRoot(root: FiberRoot, expirationTime: ExpirationTime) { if (typeof onCommitFiberRoot === 'function') { - onCommitFiberRoot(root); + onCommitFiberRoot(root, expirationTime); } } diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index 9fd797baa10d2..1aa46bd21d49e 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -1560,7 +1560,7 @@ function commitRootImpl(root) { legacyErrorBoundariesThatAlreadyFailed = null; } - onCommitRoot(finishedWork.stateNode); + onCommitRoot(finishedWork.stateNode, expirationTime); if (remainingExpirationTime === Sync) { // Count the number of times the root synchronously re-renders without