Skip to content

Commit

Permalink
fix[devtools/useTransition]: don't check for dispatch property when d…
Browse files Browse the repository at this point in the history
…etermining if hook is stateful
  • Loading branch information
hoxyq committed Sep 21, 2023
1 parent 2eed132 commit 038617d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 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,18 @@ 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 =
boundHasOwnProperty('value') &&
return boundHasOwnProperty('value') &&
boundHasOwnProperty('getSnapshot') &&
typeof queue.getSnapshot === 'function';

// These are the only types of hooks that can schedule an update.
return isStateOrReducer || isSyncExternalStore;
}

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

0 comments on commit 038617d

Please sign in to comment.