Skip to content

Commit f94d6f7

Browse files
Sebastian Silbermanneps1lon
Sebastian Silbermann
authored andcommitted
Devtools: Ensure component control flow is consistent with commit when using useDeferredValue
1 parent 7dfea96 commit f94d6f7

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
@@ -444,14 +444,15 @@ function useTransition(): [
444444

445445
function useDeferredValue<T>(value: T, initialValue?: T): T {
446446
const hook = nextHook();
447+
const prevValue = hook !== null ? hook.memoizedState : value;
447448
hookLog.push({
448449
displayName: null,
449450
primitive: 'DeferredValue',
450451
stackError: new Error(),
451-
value: hook !== null ? hook.memoizedState : value,
452+
value: prevValue,
452453
debugInfo: null,
453454
});
454-
return value;
455+
return prevValue;
455456
}
456457

457458
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)