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 8a503e433ff30..be3f6745d6192 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -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 // diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 3a7dad1b9c8a5..9d8031647b050 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index ac09110a4a517..611dcc54c32a1 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index e5dc5fe25cfee..eb0601ce34bb4 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index 6081e57da8ef4..bbeaef2b2c4d4 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 6694b6b8afeff..91613dd4df5a2 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -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); diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 2babd5bcd695c..a34757b760c44 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -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);