Skip to content
Closed
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
28 changes: 21 additions & 7 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,19 @@ export function attach(
return false;
}

function isUseSyncExternalStoreHook(hookObject: any): boolean {
const queue = hookObject.queue;
if (!queue) {
return false;
}
const boundHasOwnProperty = hasOwnProperty.bind(queue);
return (
typeof queue.getSnapshot === 'function' &&
boundHasOwnProperty('value') &&
boundHasOwnProperty('getSnapshot')
);
}

function isHookThatCanScheduleUpdate(hookObject: any) {
const queue = hookObject.queue;
if (!queue) {
Expand All @@ -1929,12 +1942,7 @@ export function attach(
return true;
}

// Detect useSyncExternalStore()
return (
boundHasOwnProperty('value') &&
boundHasOwnProperty('getSnapshot') &&
typeof queue.getSnapshot === 'function'
);
return isUseSyncExternalStoreHook(hookObject);
}

function didStatefulHookChange(prev: any, next: any): boolean {
Expand All @@ -1959,9 +1967,15 @@ export function attach(
if (didStatefulHookChange(prev, next)) {
indices.push(index);
}
if (isUseSyncExternalStoreHook(next)) {
if (next.next !== null) {
next = next.next;
prev = prev.next;
}
}
index++;
next = next.next;
prev = prev.next;
index++;
}

return indices;
Expand Down
Loading