From 6d7f4ace445e8e5bf2da96fbd844ff1fd8d76f10 Mon Sep 17 00:00:00 2001 From: James Vaughan Date: Thu, 22 Feb 2024 06:42:52 -0500 Subject: [PATCH] Add useSyncExternalStore and useTransition to getPrimitiveStackCache (#28399) ## Summary This solves the problem of the devtools extension failing to parse hook names for components that make use of `useSyncExternalStore` or `useTransition`. See #27889 ## How did you test this change? I tested this against my own codebases and against the example repro project that I linked in #27889. To test, I opened up the Components tab of the dev tools extension, selected a component with hooks that make use of `useSyncExternalStore` or `useTransition`, clicked the "parse hook names" magic wand button, and observed that it now succeeds. --- packages/react-debug-tools/src/ReactDebugHooks.js | 7 +++++++ .../src/__tests__/ReactHooksInspectionIntegration-test.js | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index e6a85b86a89d4..1b285b562e19c 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -82,6 +82,13 @@ function getPrimitiveStackCache(): Map> { Dispatcher.useImperativeHandle(undefined, () => null); Dispatcher.useDebugValue(null); Dispatcher.useCallback(() => {}); + Dispatcher.useTransition(); + Dispatcher.useSyncExternalStore( + () => () => {}, + () => null, + () => null, + ); + Dispatcher.useDeferredValue(null); Dispatcher.useMemo(() => null); if (typeof Dispatcher.useMemoCache === 'function') { // This type check is for Flow only. diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index a74bbe9ca2817..1fc54ef0f9102 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -928,7 +928,7 @@ describe('ReactHooksInspectionIntegration', () => { "hookSource": { "columnNumber": 0, "fileName": "**", - "functionName": null, + "functionName": "Foo", "lineNumber": 0, }, "id": 0, @@ -986,7 +986,7 @@ describe('ReactHooksInspectionIntegration', () => { "hookSource": { "columnNumber": 0, "fileName": "**", - "functionName": null, + "functionName": "Foo", "lineNumber": 0, }, "id": 0, @@ -1969,7 +1969,7 @@ describe('ReactHooksInspectionIntegration', () => { "hookSource": { "columnNumber": 0, "fileName": "**", - "functionName": null, + "functionName": "Foo", "lineNumber": 0, }, "id": 0,