Skip to content

Commit

Permalink
Delete __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED from Reac…
Browse files Browse the repository at this point in the history
…t 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
```
  • Loading branch information
yungsters authored Oct 16, 2024
1 parent 77b637d commit a3d9ea0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 79 deletions.
15 changes: 0 additions & 15 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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<number, FiberRoot>();

const Internals = {
computeComponentStackForErrorReporting,
};

export {
// This is needed for implementation details of TouchableNativeFeedback
// Remove this once TouchableNativeFeedback doesn't use cloneElement
Expand All @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ declare const ensureNativeMethodsAreSynced: NativeMethods;
export type HostInstance = NativeMethods;
export type HostComponent<Config> = AbstractComponent<Config, HostInstance>;

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,
...
Expand Down Expand Up @@ -233,7 +226,6 @@ export type ReactNativeType = {
unmountComponentAtNode(containerTag: number): void,
unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
+unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
+__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsType,
...
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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 (
<FunctionComponent>
<View foo="test" ref={ref} />
</FunctionComponent>
);
}
}

ReactNative.render(<ClassComponent />, 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 **)',
);
});
});

0 comments on commit a3d9ea0

Please sign in to comment.