Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTR] Add usage warning behind flag #27903

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ import {checkPropStringCoercion} from 'shared/CheckStringCoercion';

import {getPublicInstance} from './ReactFiberConfigTestHost';
import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
import {allowConcurrentByDefault} from 'shared/ReactFeatureFlags';
import {
allowConcurrentByDefault,
enableReactTestRendererWarning,
} from 'shared/ReactFeatureFlags';

const act = React.act;

Expand Down Expand Up @@ -471,6 +474,14 @@ function create(
getInstance(): React$Component<any, any> | PublicInstance | null,
unstable_flushSync: typeof flushSync,
} {
if (__DEV__) {
if (enableReactTestRendererWarning === true) {
console.warn(
'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
);
}
}

let createNodeMock = defaultTestOptions.createNodeMock;
let isConcurrent = false;
let isStrictMode = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ function cleanNodeOrArray(node) {
}

describe('ReactTestRenderer', () => {
beforeEach(() => {
jest.resetModules();
ReactFeatureFlags.enableReactTestRendererWarning = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the @GATE pragma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next PR we silence the warning to allow us to turn the flag on before all the React test cleanup is finished. So for now we don't necessarily expect a pass/fail on each side of the flag. Can probably update in the future or we'll see if we can remove the flag altogether

});

it('should warn if enableReactTestRendererWarning is enabled', () => {
ReactFeatureFlags.enableReactTestRendererWarning = true;
expect(() => {
ReactTestRenderer.create(<div />);
}).toWarnDev(
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
{withoutStack: true},
);
});

it('renders a simple component', () => {
function Link() {
return <a role="link" />;
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ export const enableInfiniteRenderLoopDetection = true;
// during element creation.
export const enableRefAsProp = __NEXT_MAJOR__;

// Not ready to break experimental yet.
// Needs more internal cleanup
// Warn on any usage of ReactTestRenderer
export const enableReactTestRendererWarning = false;

// -----------------------------------------------------------------------------
// Chopping Block
//
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,7 @@ export const enableInfiniteRenderLoopDetection = false;
// because JSX is an extremely hot path.
export const enableRefAsProp = false;

export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ export const enableServerComponentKeys = true;
// TODO: Should turn this on in next "major" RN release.
export const enableRefAsProp = false;

export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const enableInfiniteRenderLoopDetection = false;
// flags should be handled by the Fiber config.
const __NEXT_MAJOR__ = __EXPERIMENTAL__;
export const enableRefAsProp = __NEXT_MAJOR__;
export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ export const enableServerComponentKeys = true;

export const enableRefAsProp = false;

export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,7 @@ export const enableInfiniteRenderLoopDetection = false;

export const enableRefAsProp = false;

export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,7 @@ export const enableServerComponentKeys = true;
// because JSX is an extremely hot path.
export const enableRefAsProp = false;

export const enableReactTestRendererWarning = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);