diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index c82c33811539c..d0494de7293ed 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -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; @@ -471,6 +474,14 @@ function create( getInstance(): React$Component | 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; diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js b/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js index 37c17c05b08ba..36b9896952b56 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js @@ -51,6 +51,21 @@ function cleanNodeOrArray(node) { } describe('ReactTestRenderer', () => { + beforeEach(() => { + jest.resetModules(); + ReactFeatureFlags.enableReactTestRendererWarning = false; + }); + + it('should warn if enableReactTestRendererWarning is enabled', () => { + ReactFeatureFlags.enableReactTestRendererWarning = true; + expect(() => { + ReactTestRenderer.create(
); + }).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 ; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 0f8d740f64fa9..1655c4eed031e 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -187,6 +187,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 // diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 20b4ba6342f1f..1bf08bdffee0a 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -102,5 +102,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); diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index fe0458e3ded62..703c1b706c113 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -93,5 +93,7 @@ export const enableServerComponentLogs = 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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 02d8e4cff408f..7a76a71b2750a 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -98,6 +98,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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index f1d91a36e6456..166fcd587111e 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -89,5 +89,7 @@ export const enableServerComponentLogs = 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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 15a8ded7de0e7..4a4142a3fc28c 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -92,5 +92,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); diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 3e6859ada39db..f54309be42530 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -118,5 +118,7 @@ export const disableClientCache = true; export const enableServerComponentKeys = true; export const enableServerComponentLogs = true; +export const enableReactTestRendererWarning = false; + // Flow magic to verify the exports of this file match the original version. ((((null: any): ExportsType): FeatureFlagsType): ExportsType);