@samitouri / QOS-React-2 / commits / a3d9ea05bf

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 ```

Timothy Yung committed Oct 16, 2024 at 11:19 UTC a3d9ea05bf01f3c3d7aedc2d938c581ad11fd14a
3 files changed -79
packages/react-native-renderer/src/ReactNativeRenderer.js
-15
@@ -26,7 +26,6 @@ import {
26 defaultOnRecoverableError,
27 } from 'react-reconciler/src/ReactFiberReconciler';
28 // TODO: direct imports like some-package/src/* are bad. Fix me.
29 -import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack';
29 import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
30 import {
31 setBatchingImplementation,
@@ -35,7 +34,6 @@ import {
34 // Modules provided by RN:
35 import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
36
38 -import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
37 import {getInspectorDataForInstance} from './ReactNativeFiberInspector';
38 import {LegacyRoot} from 'react-reconciler/src/ReactRootTags';
39 import {
@@ -194,20 +192,8 @@ function createPortal(
192
193 setBatchingImplementation(batchedUpdatesImpl, discreteUpdates);
194
197 -function computeComponentStackForErrorReporting(reactTag: number): string {
198 - const fiber = getClosestInstanceFromNode(reactTag);
199 - if (!fiber) {
200 - return '';
201 - }
202 - return getStackByFiberInDevAndProd(fiber);
203 -}
204 -
195 const roots = new Map<number, FiberRoot>();
196
207 -const Internals = {
208 - computeComponentStackForErrorReporting,
209 -};
210 -
197 export {
198 // This is needed for implementation details of TouchableNativeFeedback
199 // Remove this once TouchableNativeFeedback doesn't use cloneElement
@@ -220,7 +206,6 @@ export {
206 unmountComponentAtNodeAndRemoveContainer,
207 createPortal,
208 batchedUpdates as unstable_batchedUpdates,
223 - Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
209 // This export is typically undefined in production builds.
210 // See the "enableGetInspectorDataForInstanceInProduction" flag.
211 getInspectorDataForInstance,
packages/react-native-renderer/src/ReactNativeTypes.js
-8
@@ -139,13 +139,6 @@ declare const ensureNativeMethodsAreSynced: NativeMethods;
139 export type HostInstance = NativeMethods;
140 export type HostComponent<Config> = AbstractComponent<Config, HostInstance>;
141
142 -type SecretInternalsType = {
143 - computeComponentStackForErrorReporting(tag: number): string,
144 - // TODO (bvaughn) Decide which additional types to expose here?
145 - // And how much information to fill in for the above types.
146 - ...
147 -};
148 -
142 type InspectorDataProps = $ReadOnly<{
143 [propName: string]: string,
144 ...
@@ -233,7 +226,6 @@ export type ReactNativeType = {
226 unmountComponentAtNode(containerTag: number): void,
227 unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
228 +unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
236 - +__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsType,
229 ...
230 };
231
packages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js
-56
@@ -10,32 +10,15 @@
10
11 'use strict';
12
13 -let React;
14 -let ReactNative;
13 let createReactNativeComponentClass;
16 -let computeComponentStackForErrorReporting;
17 -
18 -function normalizeCodeLocInfo(str) {
19 - return (
20 - str &&
21 - str.replace(/\n +(?:at|in) ([\S]+)[^\n]*/g, function (m, name) {
22 - return '\n in ' + name + ' (at **)';
23 - })
24 - );
25 -}
14
15 describe('ReactNativeError', () => {
16 beforeEach(() => {
17 jest.resetModules();
18
31 - React = require('react');
32 - ReactNative = require('react-native-renderer');
19 createReactNativeComponentClass =
20 require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
21 .ReactNativeViewConfigRegistry.register;
36 - computeComponentStackForErrorReporting =
37 - ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
38 - .computeComponentStackForErrorReporting;
22 });
23
24 it('should throw error if null component registration getter is used', () => {
@@ -49,43 +32,4 @@ describe('ReactNativeError', () => {
32 'View config getter callback for component `View` must be a function (received `null`)',
33 );
34 });
52 -
53 - // @gate !disableLegacyMode
54 - it('should be able to extract a component stack from a native view', () => {
55 - const View = createReactNativeComponentClass('View', () => ({
56 - validAttributes: {foo: true},
57 - uiViewClassName: 'View',
58 - }));
59 -
60 - const ref = React.createRef();
61 -
62 - function FunctionComponent(props) {
63 - return props.children;
64 - }
65 -
66 - class ClassComponent extends React.Component {
67 - render() {
68 - return (
69 - <FunctionComponent>
70 - <View foo="test" ref={ref} />
71 - </FunctionComponent>
72 - );
73 - }
74 - }
75 -
76 - ReactNative.render(<ClassComponent />, 1);
77 -
78 - const reactTag = ReactNative.findNodeHandle(ref.current);
79 -
80 - const componentStack = normalizeCodeLocInfo(
81 - computeComponentStackForErrorReporting(reactTag),
82 - );
83 -
84 - expect(componentStack).toBe(
85 - '\n' +
86 - ' in View (at **)\n' +
87 - ' in FunctionComponent (at **)\n' +
88 - ' in ClassComponent (at **)',
89 - );
90 - });
35 });