From 9cae4428a13c1377df9b4a752f8d87646df461ec Mon Sep 17 00:00:00 2001 From: Josh Story Date: Wed, 6 Dec 2023 12:57:14 -0800 Subject: [PATCH 01/11] Update act references in tests (#27805) As part of the process of removing the deprecated `react-dom/test-utils` package references to `act` from this module are replaced with references to `unstable_act` in `react`. It is likely that the unstable act implementation will be made stable. The test utils act is just a reexport of the unstable_act implementation in react itself. --- fixtures/dom/src/__tests__/nested-act-test.js | 4 ++-- packages/react-devtools-shared/src/__tests__/utils.js | 4 ++-- .../react-dom/src/__tests__/ReactDOMHydrationDiff-test.js | 2 +- .../src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js | 2 +- packages/react-refresh/src/__tests__/ReactFresh-test.js | 4 ++-- .../react-refresh/src/__tests__/ReactFreshIntegration-test.js | 2 +- .../src/__tests__/ReactFlightDOMForm-test.js | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fixtures/dom/src/__tests__/nested-act-test.js b/fixtures/dom/src/__tests__/nested-act-test.js index d57bef7310e41..4a4c63eaad105 100644 --- a/fixtures/dom/src/__tests__/nested-act-test.js +++ b/fixtures/dom/src/__tests__/nested-act-test.js @@ -20,7 +20,7 @@ describe('unmocked scheduler', () => { beforeEach(() => { jest.resetModules(); React = require('react'); - DOMAct = require('react-dom/test-utils').act; + DOMAct = React.unstable_act; TestRenderer = require('react-test-renderer'); TestAct = TestRenderer.act; }); @@ -61,7 +61,7 @@ describe('mocked scheduler', () => { require.requireActual('scheduler/unstable_mock') ); React = require('react'); - DOMAct = require('react-dom/test-utils').act; + DOMAct = React.unstable_act; TestRenderer = require('react-test-renderer'); TestAct = TestRenderer.act; }); diff --git a/packages/react-devtools-shared/src/__tests__/utils.js b/packages/react-devtools-shared/src/__tests__/utils.js index 0c5a0b09f7d01..bf5a8b98eab23 100644 --- a/packages/react-devtools-shared/src/__tests__/utils.js +++ b/packages/react-devtools-shared/src/__tests__/utils.js @@ -19,7 +19,7 @@ export function act( recursivelyFlush: boolean = true, ): void { const {act: actTestRenderer} = require('react-test-renderer'); - const {act: actDOM} = require('react-dom/test-utils'); + const actDOM = require('react').unstable_act; actDOM(() => { actTestRenderer(() => { @@ -44,7 +44,7 @@ export async function actAsync( recursivelyFlush: boolean = true, ): Promise { const {act: actTestRenderer} = require('react-test-renderer'); - const {act: actDOM} = require('react-dom/test-utils'); + const actDOM = require('react').unstable_act; await actDOM(async () => { await actTestRenderer(async () => { diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js index 3bdcd9c16a966..45de6fa9104f4 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js @@ -25,7 +25,7 @@ describe('ReactDOMServerHydration', () => { React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; console.error = jest.fn(); container = document.createElement('div'); diff --git a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js index e0bce1c01ca69..a38d4c0698ced 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js @@ -37,7 +37,7 @@ beforeEach(() => { yields = []; React = require('react'); ReactDOM = require('react-dom'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; container = document.createElement('div'); document.body.appendChild(container); }); diff --git a/packages/react-refresh/src/__tests__/ReactFresh-test.js b/packages/react-refresh/src/__tests__/ReactFresh-test.js index aa7b2504227e0..8ce009ed72043 100644 --- a/packages/react-refresh/src/__tests__/ReactFresh-test.js +++ b/packages/react-refresh/src/__tests__/ReactFresh-test.js @@ -34,7 +34,7 @@ describe('ReactFresh', () => { ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; internalAct = require('internal-test-utils').act; const InternalTestUtils = require('internal-test-utils'); @@ -3792,7 +3792,7 @@ describe('ReactFresh', () => { React = require('react'); ReactDOM = require('react-dom'); Scheduler = require('scheduler'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; internalAct = require('internal-test-utils').act; // Important! Inject into the global hook *after* ReactDOM runs: diff --git a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js index 54e596f6232c3..ee7a9230bb14e 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js @@ -31,7 +31,7 @@ describe('ReactFreshIntegration', () => { ReactFreshRuntime = require('react-refresh/runtime'); ReactFreshRuntime.injectIntoGlobalHook(global); ReactDOM = require('react-dom'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; container = document.createElement('div'); document.body.appendChild(container); exportsObj = undefined; diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js index d21c456b8e087..89b436907f201 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js @@ -54,7 +54,7 @@ describe('ReactFlightDOMForm', () => { ReactServerDOMClient = require('react-server-dom-webpack/client.edge'); ReactDOMServer = require('react-dom/server.edge'); ReactDOMClient = require('react-dom/client'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; useFormState = require('react-dom').useFormState; container = document.createElement('div'); document.body.appendChild(container); From be8aa76873e231555676483a36534bb48ad1b1a3 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Wed, 6 Dec 2023 16:02:52 -0500 Subject: [PATCH 02/11] Enable flag disableModulePatternComponents for native-fb (#27807) #27742 will remove this feature flag altogether, this just already removes the dynamic flag for the Meta React Native build ahead of time. --- packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js | 1 - packages/shared/forks/ReactFeatureFlags.native-fb.js | 2 +- scripts/flow/xplat.js | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js b/packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js index 4d488410a55db..91a518a905154 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js @@ -21,7 +21,6 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags'; // update the test configuration. export const alwaysThrottleRetries = __VARIANT__; -export const disableModulePatternComponents = __VARIANT__; export const enableDeferRootSchedulingToMicrotask = __VARIANT__; export const enableUnifiedSyncLane = __VARIANT__; export const enableUseRefAccessWarning = __VARIANT__; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 3d228b88440be..c293ebafd6d0b 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -19,7 +19,6 @@ import * as dynamicFlags from 'ReactNativeInternalFeatureFlags'; // the exports object every time a flag is read. export const { alwaysThrottleRetries, - disableModulePatternComponents, enableDeferRootSchedulingToMicrotask, enableUnifiedSyncLane, enableUseRefAccessWarning, @@ -28,6 +27,7 @@ export const { } = dynamicFlags; // The rest of the flags are static for better dead code elimination. +export const disableModulePatternComponents = true; export const enableDebugTracing = false; export const enableSchedulingProfiler = __PROFILE__; export const enableProfilerTimer = __PROFILE__; diff --git a/scripts/flow/xplat.js b/scripts/flow/xplat.js index fadbe3161aa26..b2c4709a3b566 100644 --- a/scripts/flow/xplat.js +++ b/scripts/flow/xplat.js @@ -9,7 +9,6 @@ declare module 'ReactNativeInternalFeatureFlags' { declare export var alwaysThrottleRetries: boolean; - declare export var disableModulePatternComponents: boolean; declare export var enableDeferRootSchedulingToMicrotask: boolean; declare export var enableUnifiedSyncLane: boolean; declare export var enableUseRefAccessWarning: boolean; From b36ae8d7aab94dae285d9d6a1c5f004e6fc19fc9 Mon Sep 17 00:00:00 2001 From: Jack Pope Date: Thu, 7 Dec 2023 10:26:33 -0500 Subject: [PATCH 03/11] Add stable concurrent option to react-test-renderer (#27804) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Concurrent rendering has been the default since React 18 release. ReactTestRenderer requires passing `{unstable_isConcurrent: true}` to match this behavior, which means by default tests written with RTR use a different rendering method than the code they test. Eventually, RTR should only use ConcurrentRoot. As a first step, let's add a version of the concurrent option that isn't marked unstable. Next we will follow up with removing the unstable option when it is safe to merge. ## How did you test this change? `yarn test packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js` --- .../__tests__/ReactCacheOld-test.internal.js | 14 +++--- .../ReactDevToolsHooksIntegration-test.js | 2 +- .../src/__tests__/inspectedElement-test.js | 12 ++--- .../__tests__/DebugTracing-test.internal.js | 18 +++---- ...rorBoundaryReconciliation-test.internal.js | 2 +- .../src/__tests__/ReactHooks-test.internal.js | 16 +++--- .../src/__tests__/ReactLazy-test.internal.js | 50 +++++++++---------- .../__tests__/ReactSuspense-test.internal.js | 26 +++++----- .../src/__tests__/StrictEffectsMode-test.js | 22 ++++---- .../src/ReactTestRenderer.js | 6 ++- .../__tests__/ReactTestRendererAsync-test.js | 8 +-- .../__tests__/ReactProfiler-test.internal.js | 12 ++--- ...ofilerDevToolsIntegration-test.internal.js | 2 +- .../__tests__/ReactStartTransition-test.js | 2 +- .../src/__tests__/useSubscription-test.js | 18 +++---- 15 files changed, 107 insertions(+), 103 deletions(-) diff --git a/packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js b/packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js index 9463b72e14a69..2403d2de286b1 100644 --- a/packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js +++ b/packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js @@ -121,7 +121,7 @@ describe('ReactCache', () => { } ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [Hi]', 'Loading...']); @@ -141,7 +141,7 @@ describe('ReactCache', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [Hi]', 'Loading...']); @@ -181,7 +181,7 @@ describe('ReactCache', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -210,7 +210,7 @@ describe('ReactCache', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Suspend! [1]', 'Loading...']); @@ -298,7 +298,7 @@ describe('ReactCache', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -356,7 +356,7 @@ describe('ReactCache', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -372,7 +372,7 @@ describe('ReactCache', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); diff --git a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js index 5da6b8de2a42e..eabcbd215bfb2 100644 --- a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js @@ -254,7 +254,7 @@ describe('React hooks DevTools integration', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); diff --git a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js index 891e4f3e73834..cba7b3b2e7b61 100644 --- a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js +++ b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js @@ -75,7 +75,7 @@ describe('InspectedElement', () => { // Used by inspectElementAtIndex() helper function utils.act(() => { testRendererInstance = TestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -307,7 +307,7 @@ describe('InspectedElement', () => { ['An update to %s inside a test was not wrapped in act'], () => { testRendererInstance = TestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); }, ); @@ -469,7 +469,7 @@ describe('InspectedElement', () => { ['An update to %s inside a test was not wrapped in act'], () => { testRendererInstance = TestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); }, ); @@ -2034,7 +2034,7 @@ describe('InspectedElement', () => { ['An update to %s inside a test was not wrapped in act'], () => { testRendererInstance = TestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); }, ); @@ -2317,7 +2317,7 @@ describe('InspectedElement', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }, false); await utils.actAsync(() => { @@ -2817,7 +2817,7 @@ describe('InspectedElement', () => { ['An update to %s inside a test was not wrapped in act'], () => { testRendererInstance = TestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); }, ); diff --git a/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js b/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js index f8026d6ea9fab..041086690e7fe 100644 --- a/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js +++ b/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js @@ -67,7 +67,7 @@ describe('DebugTracing', () => {
, - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); expect(logs).toEqual([]); @@ -179,7 +179,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); @@ -216,7 +216,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); @@ -247,7 +247,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); @@ -278,7 +278,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); }).toErrorDev('Cannot update during an existing state transition'); @@ -305,7 +305,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); @@ -333,7 +333,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); expect(logs).toEqual([ @@ -358,7 +358,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -381,7 +381,7 @@ describe('DebugTracing', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ), ); diff --git a/packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js b/packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js index 71e047afc5ff6..0ce51699849b7 100644 --- a/packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js @@ -59,7 +59,7 @@ describe('ErrorBoundaryReconciliation', () => { , - {unstable_isConcurrent: isConcurrent}, + {isConcurrent: isConcurrent}, ); }); expect(renderer).toMatchRenderedOutput(); diff --git a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js index 5f09cf997907c..5da503c8ca34d 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js @@ -86,7 +86,7 @@ describe('ReactHooks', () => { return ; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Parent: 0, 0', 'Child: 0, 0', 'Effect: 0, 0']); expect(root).toMatchRenderedOutput('0, 0'); @@ -174,7 +174,7 @@ describe('ReactHooks', () => { Parent = memo(Parent); - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Parent: 0, 0 (light)', 'Child: 0, 0 (light)']); expect(root).toMatchRenderedOutput('0, 0 (light)'); @@ -232,7 +232,7 @@ describe('ReactHooks', () => { return counter; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Count: 0']); expect(root).toMatchRenderedOutput('0'); @@ -266,7 +266,7 @@ describe('ReactHooks', () => { return counter; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Count: 0']); expect(root).toMatchRenderedOutput('0'); @@ -322,7 +322,7 @@ describe('ReactHooks', () => { }); return ; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); await act(() => { root.update( @@ -390,7 +390,7 @@ describe('ReactHooks', () => { return ; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Parent: 0', 'Child: 0', 'Effect: 0']); expect(root).toMatchRenderedOutput('0'); @@ -465,7 +465,7 @@ describe('ReactHooks', () => { return ; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Parent: 0', 'Child: 0']); expect(root).toMatchRenderedOutput('0'); @@ -523,7 +523,7 @@ describe('ReactHooks', () => { return ; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); root.update(); await waitForAll(['Parent: 1', 'Child: 1']); expect(root).toMatchRenderedOutput('1'); diff --git a/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js b/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js index a96c60bc26e88..36e956256dc60 100644 --- a/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js @@ -99,7 +99,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -185,7 +185,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -208,7 +208,7 @@ describe('ReactLazy', () => { const LazyText = lazy(async () => Text); const root = ReactTestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); let error; @@ -242,7 +242,7 @@ describe('ReactLazy', () => { }); const root = ReactTestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); let error; @@ -302,7 +302,7 @@ describe('ReactLazy', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [LazyChildA]', 'Loading...']); @@ -337,7 +337,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -394,7 +394,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Loading...']); @@ -440,7 +440,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Not lazy: 0', 'Loading...']); @@ -485,7 +485,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Not lazy: 0', 'Loading...']); @@ -561,7 +561,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -691,7 +691,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -734,7 +734,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -761,7 +761,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -815,7 +815,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -1012,7 +1012,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -1055,7 +1055,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -1100,7 +1100,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -1131,7 +1131,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Loading...']); @@ -1218,7 +1218,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Loading...']); @@ -1264,7 +1264,7 @@ describe('ReactLazy', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -1304,7 +1304,7 @@ describe('ReactLazy', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); await waitForAll(['Loading...']); @@ -1412,7 +1412,7 @@ describe('ReactLazy', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Init A', 'Loading...']); @@ -1497,7 +1497,7 @@ describe('ReactLazy', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: false, + isConcurrent: false, }); assertLog(['Init A', 'Init B', 'Loading...']); @@ -1559,7 +1559,7 @@ describe('ReactLazy', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Init A', 'Loading...']); @@ -1628,7 +1628,7 @@ describe('ReactLazy', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: false, + isConcurrent: false, }); assertLog(['Init A', 'Loading...']); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js index 6e347b900f655..4440f900294a7 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js @@ -117,7 +117,7 @@ describe('ReactSuspense', () => { // Render an empty shell const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Foo']); @@ -158,7 +158,7 @@ describe('ReactSuspense', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); @@ -217,7 +217,7 @@ describe('ReactSuspense', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Initial']); @@ -268,7 +268,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Foo', 'Suspend! [A]', 'Loading...']); @@ -303,7 +303,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Foo', 'Suspend! [A]', 'Loading...']); @@ -353,7 +353,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(null, { - unstable_isConcurrent: true, + isConcurrent: true, }); root.update(); @@ -456,7 +456,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [default]', 'Loading...']); @@ -502,7 +502,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [default]', 'Loading...']); @@ -545,7 +545,7 @@ describe('ReactSuspense', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Suspend! [default]', 'Loading...']); @@ -589,7 +589,7 @@ describe('ReactSuspense', () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); await waitForAll(['Suspend! [default]', 'Loading...']); @@ -631,7 +631,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Child 1', 'create layout']); @@ -899,7 +899,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); // Initial render @@ -990,7 +990,7 @@ describe('ReactSuspense', () => { } const root = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['Suspend! [Child 1]', 'Loading...']); diff --git a/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js b/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js index f7c30616c98c1..af35defe2325c 100644 --- a/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js +++ b/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js @@ -76,7 +76,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -129,7 +129,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -182,7 +182,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -233,7 +233,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -286,7 +286,7 @@ describe('StrictEffectsMode', () => { } await act(() => { - ReactTestRenderer.create(, {unstable_isConcurrent: true}); + ReactTestRenderer.create(, {isConcurrent: true}); }); if (supportsDoubleInvokeEffects()) { @@ -322,7 +322,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -367,7 +367,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -438,7 +438,7 @@ describe('StrictEffectsMode', () => { await act(() => { ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -502,7 +502,7 @@ describe('StrictEffectsMode', () => { } await act(() => { - ReactTestRenderer.create(, {unstable_isConcurrent: true}); + ReactTestRenderer.create(, {isConcurrent: true}); }); if (supportsDoubleInvokeEffects()) { @@ -586,7 +586,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -667,7 +667,7 @@ describe('StrictEffectsMode', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index 273bcd128f47c..4b19f599db5ac 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -60,6 +60,7 @@ const act = React.unstable_act; type TestRendererOptions = { createNodeMock: (element: React$Element) => any, + isConcurrent: boolean, unstable_isConcurrent: boolean, unstable_strictMode: boolean, unstable_concurrentUpdatesByDefault: boolean, @@ -479,7 +480,10 @@ function create( // $FlowFixMe[incompatible-type] found when upgrading Flow createNodeMock = options.createNodeMock; } - if (options.unstable_isConcurrent === true) { + if ( + options.unstable_isConcurrent === true || + options.isConcurrent === true + ) { isConcurrent = true; } if (options.unstable_strictMode === true) { diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js b/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js index 468f62d39a722..51c7e0a950ddc 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js @@ -34,7 +34,7 @@ describe('ReactTestRendererAsync', () => { return props.children; } const renderer = ReactTestRenderer.create(Hi, { - unstable_isConcurrent: true, + isConcurrent: true, }); // Before flushing, nothing has mounted. @@ -68,7 +68,7 @@ describe('ReactTestRendererAsync', () => { ); } const renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); await waitForAll(['A:1', 'B:1', 'C:1']); @@ -97,7 +97,7 @@ describe('ReactTestRendererAsync', () => { let renderer; React.startTransition(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); @@ -137,7 +137,7 @@ describe('ReactTestRendererAsync', () => { let renderer; React.startTransition(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); diff --git a/packages/react/src/__tests__/ReactProfiler-test.internal.js b/packages/react/src/__tests__/ReactProfiler-test.internal.js index 25386df33abcf..fd42561393101 100644 --- a/packages/react/src/__tests__/ReactProfiler-test.internal.js +++ b/packages/react/src/__tests__/ReactProfiler-test.internal.js @@ -213,7 +213,7 @@ describe(`onRender`, () => { , { - unstable_isConcurrent: true, + isConcurrent: true, }, ); }); @@ -752,7 +752,7 @@ describe(`onRender`, () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -793,7 +793,7 @@ describe(`onRender`, () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -844,7 +844,7 @@ describe(`onRender`, () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -897,7 +897,7 @@ describe(`onRender`, () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); // Render everything initially. @@ -1002,7 +1002,7 @@ describe(`onRender`, () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); // Render everything initially. diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index d28e2ad8de64a..572abd354da63 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -150,7 +150,7 @@ describe('ReactProfiler DevTools integration', () => { return text; } - const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); + const root = ReactTestRenderer.create(null, {isConcurrent: true}); // Commit something root.update(); diff --git a/packages/react/src/__tests__/ReactStartTransition-test.js b/packages/react/src/__tests__/ReactStartTransition-test.js index 9e689ac6e7105..c98372a7c74b7 100644 --- a/packages/react/src/__tests__/ReactStartTransition-test.js +++ b/packages/react/src/__tests__/ReactStartTransition-test.js @@ -49,7 +49,7 @@ describe('ReactStartTransition', () => { await act(() => { ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); diff --git a/packages/use-subscription/src/__tests__/useSubscription-test.js b/packages/use-subscription/src/__tests__/useSubscription-test.js index 19eba0a15be8e..9c971bd14bbb3 100644 --- a/packages/use-subscription/src/__tests__/useSubscription-test.js +++ b/packages/use-subscription/src/__tests__/useSubscription-test.js @@ -84,7 +84,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); assertLog(['default']); @@ -136,7 +136,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); assertLog(['initial']); @@ -185,7 +185,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -244,7 +244,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); @@ -331,7 +331,7 @@ describe('useSubscription', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); assertLog(['Child: a-0', 'Grandchild: a-0']); @@ -434,7 +434,7 @@ describe('useSubscription', () => { let renderer; await act(() => { renderer = ReactTestRenderer.create(, { - unstable_isConcurrent: true, + isConcurrent: true, }); }); assertLog(['Child: a-0', 'Grandchild: a-0']); @@ -532,7 +532,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); assertLog([true]); @@ -566,7 +566,7 @@ describe('useSubscription', () => { await act(() => { renderer = ReactTestRenderer.create( , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); }); await waitForAll([]); @@ -607,7 +607,7 @@ describe('useSubscription', () => { , - {unstable_isConcurrent: true}, + {isConcurrent: true}, ); await waitForAll(['render:first:A', 'render:second:A']); From af1fc87b54686d5e15204cd588e2227a92ae40ac Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Thu, 7 Dec 2023 17:08:52 -0500 Subject: [PATCH 04/11] [meta] copy ReactAllWarnings.js file (#27811) I recently added generation of this file in #27786, which builds the file in CircleCI, but missed actually copying it to the facebook build on GitHub Actions. This adds the later. --- .github/workflows/commit_artifacts.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/commit_artifacts.yml b/.github/workflows/commit_artifacts.yml index 2e5007982b1cb..86c6e70bf2341 100644 --- a/.github/workflows/commit_artifacts.yml +++ b/.github/workflows/commit_artifacts.yml @@ -120,7 +120,7 @@ jobs: - name: Move relevant files for React in www into compiled run: | mkdir -p ./compiled - mkdir -p ./compiled/facebook-www + mkdir -p ./compiled/facebook-www/__test_utils__ mkdir -p ./compiled/babel-plugin-react-refresh # Copy the facebook-www folder into compiled @@ -128,6 +128,7 @@ jobs: # Copy WARNINGS to facebook-www mv build/WARNINGS ./compiled/facebook-www/WARNINGS + mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js # Copy eslint-plugin-react-hooks into facebook-www mv build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \ From a3aae7fb01ecf4ac12a8ba53abcf0403a4c7c3f8 Mon Sep 17 00:00:00 2001 From: BIKI DAS Date: Fri, 8 Dec 2023 19:04:09 +0530 Subject: [PATCH 05/11] feat:-added tests for more coverage in reactDom-input and reactText-area (#27796) Small test similar to few tests added in #27740 , the `reactDom-input` error message was just modified to match the error message, and the `reactDomTextarea-test.js` has tests added to ensure more coverage. --- .../src/__tests__/ReactDOMInput-test.js | 15 +++- .../src/__tests__/ReactDOMTextarea-test.js | 81 +++++++++++++++++++ 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMInput-test.js b/packages/react-dom/src/__tests__/ReactDOMInput-test.js index be4b59ce0806e..6b8baaddbe023 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInput-test.js @@ -110,7 +110,10 @@ describe('ReactDOMInput', () => { expect(() => { ReactDOM.render(, container); }).toErrorDev( - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.', + 'Warning: You provided a `value` prop to a form ' + + 'field without an `onChange` handler. This will render a read-only ' + + 'field. If the field should be mutable use `defaultValue`. ' + + 'Otherwise, set either `onChange` or `readOnly`.', ); }); @@ -118,7 +121,10 @@ describe('ReactDOMInput', () => { expect(() => { ReactDOM.render(, container); }).toErrorDev( - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.', + 'Warning: You provided a `value` prop to a form ' + + 'field without an `onChange` handler. This will render a read-only ' + + 'field. If the field should be mutable use `defaultValue`. ' + + 'Otherwise, set either `onChange` or `readOnly`.', ); }); @@ -126,7 +132,10 @@ describe('ReactDOMInput', () => { expect(() => { ReactDOM.render(, container); }).toErrorDev( - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.', + 'Warning: You provided a `value` prop to a form ' + + 'field without an `onChange` handler. This will render a read-only ' + + 'field. If the field should be mutable use `defaultValue`. ' + + 'Otherwise, set either `onChange` or `readOnly`.', ); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js index 39a1bac1e9ede..810452c64a313 100644 --- a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js @@ -759,4 +759,85 @@ describe('ReactDOMTextarea', () => { ReactDOM.render(