From a3d9ea05bf01f3c3d7aedc2d938c581ad11fd14a Mon Sep 17 00:00:00 2001 From: Timothy Yung Date: Wed, 16 Oct 2024 11:19:01 -0700 Subject: [PATCH] Delete `__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` from React Native Renderer (#31276) ## Summary The React Native Renderer exports a `__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` property with a single method that has no remaining call sites: `computeComponentStackForErrorReporting` This PR cleans up this unused export. ## How did you test this change? ``` $ yarn $ yarn flow fabric $ yarn test ``` --- .../src/ReactNativeRenderer.js | 15 ----- .../src/ReactNativeTypes.js | 8 --- .../ReactNativeError-test.internal.js | 56 ------------------- 3 files changed, 79 deletions(-) diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 4ec5ab2c58529..7f959184c95ef 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -26,7 +26,6 @@ import { defaultOnRecoverableError, } from 'react-reconciler/src/ReactFiberReconciler'; // TODO: direct imports like some-package/src/* are bad. Fix me. -import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack'; import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal'; import { setBatchingImplementation, @@ -35,7 +34,6 @@ import { // Modules provided by RN: import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; -import {getClosestInstanceFromNode} from './ReactNativeComponentTree'; import {getInspectorDataForInstance} from './ReactNativeFiberInspector'; import {LegacyRoot} from 'react-reconciler/src/ReactRootTags'; import { @@ -194,20 +192,8 @@ function createPortal( setBatchingImplementation(batchedUpdatesImpl, discreteUpdates); -function computeComponentStackForErrorReporting(reactTag: number): string { - const fiber = getClosestInstanceFromNode(reactTag); - if (!fiber) { - return ''; - } - return getStackByFiberInDevAndProd(fiber); -} - const roots = new Map(); -const Internals = { - computeComponentStackForErrorReporting, -}; - export { // This is needed for implementation details of TouchableNativeFeedback // Remove this once TouchableNativeFeedback doesn't use cloneElement @@ -220,7 +206,6 @@ export { unmountComponentAtNodeAndRemoveContainer, createPortal, batchedUpdates as unstable_batchedUpdates, - Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, // This export is typically undefined in production builds. // See the "enableGetInspectorDataForInstanceInProduction" flag. getInspectorDataForInstance, diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index 03c03cfba0072..540ac1cf2aa70 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -139,13 +139,6 @@ declare const ensureNativeMethodsAreSynced: NativeMethods; export type HostInstance = NativeMethods; export type HostComponent = AbstractComponent; -type SecretInternalsType = { - computeComponentStackForErrorReporting(tag: number): string, - // TODO (bvaughn) Decide which additional types to expose here? - // And how much information to fill in for the above types. - ... -}; - type InspectorDataProps = $ReadOnly<{ [propName: string]: string, ... @@ -233,7 +226,6 @@ export type ReactNativeType = { unmountComponentAtNode(containerTag: number): void, unmountComponentAtNodeAndRemoveContainer(containerTag: number): void, +unstable_batchedUpdates: (fn: (T) => void, bookkeeping: T) => void, - +__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsType, ... }; diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js index a7ac05b214492..8eb6421d49250 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js @@ -10,32 +10,15 @@ 'use strict'; -let React; -let ReactNative; let createReactNativeComponentClass; -let computeComponentStackForErrorReporting; - -function normalizeCodeLocInfo(str) { - return ( - str && - str.replace(/\n +(?:at|in) ([\S]+)[^\n]*/g, function (m, name) { - return '\n in ' + name + ' (at **)'; - }) - ); -} describe('ReactNativeError', () => { beforeEach(() => { jest.resetModules(); - React = require('react'); - ReactNative = require('react-native-renderer'); createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') .ReactNativeViewConfigRegistry.register; - computeComponentStackForErrorReporting = - ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED - .computeComponentStackForErrorReporting; }); it('should throw error if null component registration getter is used', () => { @@ -49,43 +32,4 @@ describe('ReactNativeError', () => { 'View config getter callback for component `View` must be a function (received `null`)', ); }); - - // @gate !disableLegacyMode - it('should be able to extract a component stack from a native view', () => { - const View = createReactNativeComponentClass('View', () => ({ - validAttributes: {foo: true}, - uiViewClassName: 'View', - })); - - const ref = React.createRef(); - - function FunctionComponent(props) { - return props.children; - } - - class ClassComponent extends React.Component { - render() { - return ( - - - - ); - } - } - - ReactNative.render(, 1); - - const reactTag = ReactNative.findNodeHandle(ref.current); - - const componentStack = normalizeCodeLocInfo( - computeComponentStackForErrorReporting(reactTag), - ); - - expect(componentStack).toBe( - '\n' + - ' in View (at **)\n' + - ' in FunctionComponent (at **)\n' + - ' in ClassComponent (at **)', - ); - }); });