mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Inform DevTools of commit priority level (#15664)
* Pass inferred priority level to DevTools commit hook in PROFILE mode
This commit is contained in:
+44
-25
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user