Skip to content
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

fix[devtools/useTransition]: don't check for dispatch property when determining if hook is stateful #27365

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1419,22 +1419,20 @@ export function attach(

const boundHasOwnProperty = hasOwnProperty.bind(queue);

// Detect the shape of useState() or useReducer()
// Detect the shape of useState() / useReducer() / useTransition()
// using the attributes that are unique to these hooks
// but also stable (e.g. not tied to current Lanes implementation)
const isStateOrReducer =
boundHasOwnProperty('pending') &&
boundHasOwnProperty('dispatch') &&
typeof queue.dispatch === 'function';
// We don't check for dispatch property, because useTransition doesn't have it
if (boundHasOwnProperty('pending')) {
return true;
}

// Detect useSyncExternalStore()
const isSyncExternalStore =
return (
boundHasOwnProperty('value') &&
boundHasOwnProperty('getSnapshot') &&
typeof queue.getSnapshot === 'function';

// These are the only types of hooks that can schedule an update.
return isStateOrReducer || isSyncExternalStore;
typeof queue.getSnapshot === 'function'
);
}

function didStatefulHookChange(prev: any, next: any): boolean {
Expand Down