Skip to content

Commit 4974448

Browse files
author
Sebastian Silbermann
committed
Devtools: Ensure component control flow is consistent with commit when using useDeferredValue
1 parent 24a37de commit 4974448

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,15 @@ function useTransition(): [
461461

462462
function useDeferredValue<T>(value: T, initialValue?: T): T {
463463
const hook = nextHook();
464+
const prevValue = hook !== null ? hook.memoizedState : value;
464465
hookLog.push({
465466
displayName: null,
466467
primitive: 'DeferredValue',
467468
stackError: new Error(),
468-
value: hook !== null ? hook.memoizedState : value,
469+
value: prevValue,
469470
debugInfo: null,
470471
});
471-
return value;
472+
return prevValue;
472473
}
473474

474475
function useId(): string {

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,20 @@ describe('ReactHooksInspectionIntegration', () => {
13481348
"subHooks": [],
13491349
"value": false,
13501350
},
1351+
{
1352+
"debugInfo": null,
1353+
"hookSource": {
1354+
"columnNumber": 0,
1355+
"fileName": "**",
1356+
"functionName": "Foo",
1357+
"lineNumber": 0,
1358+
},
1359+
"id": null,
1360+
"isStateEditable": false,
1361+
"name": "Context",
1362+
"subHooks": [],
1363+
"value": "provided",
1364+
},
13511365
{
13521366
"debugInfo": null,
13531367
"hookSource": {

0 commit comments

Comments
 (0)