-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Improve the detection of changed hooks #35123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Improve the detection of changed hooks #35123
Conversation
|
Comparing: bbe3f4d...f565055 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
|
@hoxyq I may need your help... Two tests are failing and I don't understand what's wrong
They only fail when I call: const prevHooks = inspectHooks(prevFiber);
const nextHooks = inspectHooks(nextFiber);I’ve narrowed it to this: export function inspectHooks<Props>(
renderFunction: (props: Props) => React$Node,
props: Props,
currentDispatcher?: CurrentDispatcherRef,
): HooksTree {
if (currentDispatcher == null) {
currentDispatcher = ReactSharedInternals;
}
const previousDispatcher = currentDispatcher.H;
currentDispatcher.H = DispatcherProxy;
let readHookLog;
let ancestorStackError;
try {
ancestorStackError = new Error();
renderFunction(props);
} catch (error) {
handleRenderFunctionError(error);
} finally {
readHookLog = hookLog;
hookLog = [];
// $FlowFixMe[incompatible-use] found when upgrading Flow
currentDispatcher.H = previousDispatcher;
}
const rootStack =
ancestorStackError === undefined
? ([]: ParsedStackFrame[])
: ErrorStackParser.parse(ancestorStackError);
return buildTree(rootStack, readHookLog);
}I suspect the issue comes from how |
Summary
cc @hoxyq
Fixes #28584. Follow up to PR: #34547
This PR updates getChangedHooksIndices to account for the fact that
useSyncExternalStore,useTransition,useActionState,useFormStateinternally mounts more than one hook while DevTools should treat it as a single user-facing hook.Approach idea came from this comment 😄
Before:
QuickTime.movie.2.mov
After:
QuickTime.movie.mov
How did you test this change?
I used this component to reproduce this issue locally (I followed instructions in
packages/react-devtools/CONTRIBUTING.md).Details