From f94d6f746c5b62554fcf8bd5c679a85de8ee5128 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 6 Mar 2024 18:18:35 +0100 Subject: [PATCH] Devtools: Ensure component control flow is consistent with commit when using `useDeferredValue` --- packages/react-debug-tools/src/ReactDebugHooks.js | 5 +++-- .../ReactHooksInspectionIntegration-test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index 20e3d89e1bf64..8e1809435d724 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -444,14 +444,15 @@ function useTransition(): [ function useDeferredValue(value: T, initialValue?: T): T { const hook = nextHook(); + const prevValue = hook !== null ? hook.memoizedState : value; hookLog.push({ displayName: null, primitive: 'DeferredValue', stackError: new Error(), - value: hook !== null ? hook.memoizedState : value, + value: prevValue, debugInfo: null, }); - return value; + return prevValue; } function useId(): string { diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index e741a84063d43..61eefa844aece 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -1348,6 +1348,20 @@ describe('ReactHooksInspectionIntegration', () => { "subHooks": [], "value": false, }, + { + "debugInfo": null, + "hookSource": { + "columnNumber": 0, + "fileName": "**", + "functionName": "Foo", + "lineNumber": 0, + }, + "id": null, + "isStateEditable": false, + "name": "Context", + "subHooks": [], + "value": "provided", + }, { "debugInfo": null, "hookSource": {