From 26ca802e8462e978282180e6cfd65e644d67bbc7 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Mon, 24 Mar 2025 12:31:58 -0700 Subject: [PATCH] Remove `__REACT_DEVTOOLS_GLOBAL_HOOK__ ` from react-native libdef (#50223) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50223 This is an implementation detail of React and better not make it leak everywhere. It's not used quite often even in react-native codebase, so it's better to just suppress the error on each call site. Currently it's typed as any, so there is not much type safety lost anyways. Changelog: [Internal] Reviewed By: alexmckenley Differential Revision: D71687426 fbshipit-source-id: 7373bcd9bedcfcb95a10fa02e6a04399ccab91f0 --- .../Libraries/Debugging/DebuggingOverlayRegistry.js | 4 ++-- .../react-native/Libraries/ReactNative/AppContainer-dev.js | 4 ++-- packages/react-native/interface.js | 4 ---- .../src/private/inspector/getInspectorDataForViewAtPoint.js | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/react-native/Libraries/Debugging/DebuggingOverlayRegistry.js b/packages/react-native/Libraries/Debugging/DebuggingOverlayRegistry.js index 052805151ad..b3be031cb9e 100644 --- a/packages/react-native/Libraries/Debugging/DebuggingOverlayRegistry.js +++ b/packages/react-native/Libraries/Debugging/DebuggingOverlayRegistry.js @@ -35,8 +35,8 @@ import processColor from '../StyleSheet/processColor'; // TODO(T171193075): __REACT_DEVTOOLS_GLOBAL_HOOK__ is always injected in dev-bundles, // but it is not mocked in some Jest tests. We should update Jest tests setup, so it would be the same as expected testing environment. -const reactDevToolsHook: ?ReactDevToolsGlobalHook = - window.__REACT_DEVTOOLS_GLOBAL_HOOK__; +const reactDevToolsHook: ?ReactDevToolsGlobalHook = (window: $FlowFixMe) + .__REACT_DEVTOOLS_GLOBAL_HOOK__; export type DebuggingOverlayRegistrySubscriberProtocol = { rootViewRef: AppContainerRootViewRef, diff --git a/packages/react-native/Libraries/ReactNative/AppContainer-dev.js b/packages/react-native/Libraries/ReactNative/AppContainer-dev.js index 9b74859c72d..95012f7d785 100644 --- a/packages/react-native/Libraries/ReactNative/AppContainer-dev.js +++ b/packages/react-native/Libraries/ReactNative/AppContainer-dev.js @@ -27,8 +27,8 @@ import * as React from 'react'; const {useEffect, useState, useCallback} = React; -const reactDevToolsHook: ReactDevToolsGlobalHook = - window.__REACT_DEVTOOLS_GLOBAL_HOOK__; +const reactDevToolsHook: ReactDevToolsGlobalHook = (window: $FlowFixMe) + .__REACT_DEVTOOLS_GLOBAL_HOOK__; // Required for React DevTools to view / edit React Native styles in Flipper. // Flipper doesn't inject these values when initializing DevTools. diff --git a/packages/react-native/interface.js b/packages/react-native/interface.js index 8052785f9b5..38ae9c660b2 100644 --- a/packages/react-native/interface.js +++ b/packages/react-native/interface.js @@ -19,7 +19,3 @@ /* eslint-disable no-unused-vars */ declare var __DEV__: boolean; - -declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{ - inject: ?((stuff: Object) => void) -};*/ diff --git a/packages/react-native/src/private/inspector/getInspectorDataForViewAtPoint.js b/packages/react-native/src/private/inspector/getInspectorDataForViewAtPoint.js index d3567831ded..6496fea915a 100644 --- a/packages/react-native/src/private/inspector/getInspectorDataForViewAtPoint.js +++ b/packages/react-native/src/private/inspector/getInspectorDataForViewAtPoint.js @@ -26,14 +26,14 @@ export type ReactRenderer = { }; type AttachedRendererEventPayload = {id: number, renderer: ReactRenderer}; -const reactDevToolsHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__; +const reactDevToolsHook = (window: any).__REACT_DEVTOOLS_GLOBAL_HOOK__; invariant( Boolean(reactDevToolsHook), 'getInspectorDataForViewAtPoint should not be used if React DevTools hook is not injected', ); const renderers: Array = Array.from( - window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.values(), + (window: any).__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.values(), ); const appendRenderer = ({renderer}: AttachedRendererEventPayload) =>