From 14fd9630ee04387f4361da289393234e2b7d93b6 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 13 Feb 2024 15:04:49 +0000 Subject: [PATCH 1/6] Switch to mean (#28226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, `` was equivalent to ``. However, since the introduction of Hooks, the `` API is rarely used. The goal here is to make the common case cleaner: ```js const ThemeContext = createContext('light') function App() { return ( ... ) } function Button() { const theme = use(ThemeContext) // ... } ``` This is technically a breaking change, but we've been warning about rendering `` directly for several years by now, so it's unlikely much code in the wild depends on the old behavior. [Proof that it warns today (check console).](https://codesandbox.io/p/sandbox/peaceful-nobel-pdxtfl) --- **The relevant commit is 5696782b428a5ace96e66c1857e13249b6c07958.** It switches `createContext` implementation so that `Context.Provider === Context`. The main assumption that changed is that a Provider's fiber type is now the context itself (rather than an intermediate object). Whereas a Consumer's fiber type is now always an intermediate object (rather than it being sometimes the context itself and sometimes an intermediate object). My methodology was to start with the relevant symbols, work tags, and types, and work my way backwards to all usages. This might break tooling that depends on inspecting React's internal fields. I've added DevTools support in the second commit. This didn't need explicit versioning—the structure tells us enough. --- .../src/ReactFlightReplyClient.js | 7 +- .../react-debug-tools/src/ReactDebugHooks.js | 8 +- .../src/backend/ReactSymbols.js | 2 + .../src/backend/renderer.js | 53 ++++++- ...eactDOMServerIntegrationNewContext-test.js | 133 ++++------------ .../__tests__/ReactServerRendering-test.js | 24 ++- packages/react-is/src/ReactIs.js | 33 +++- packages/react-reconciler/src/ReactFiber.js | 25 ++- .../src/ReactFiberBeginWork.js | 53 +++---- .../src/ReactFiberClassComponent.js | 10 +- .../src/ReactFiberCompleteWork.js | 8 +- .../src/ReactFiberNewContext.js | 11 +- .../react-reconciler/src/ReactFiberScope.js | 10 +- .../src/ReactFiberUnwindWork.js | 15 +- .../src/__tests__/ReactNewContext-test.js | 111 ++----------- .../src/getComponentNameFromFiber.js | 25 ++- .../src/ReactFizzClassComponent.js | 10 +- packages/react-server/src/ReactFizzServer.js | 66 ++++---- packages/react/src/ReactContext.js | 147 ++++++++---------- packages/react/src/ReactHooks.js | 22 +-- .../__tests__/ReactContextValidator-test.js | 39 ++--- packages/shared/ReactFeatureFlags.js | 2 + packages/shared/ReactSymbols.js | 3 +- packages/shared/ReactTypes.js | 10 +- .../forks/ReactFeatureFlags.native-fb.js | 1 + .../forks/ReactFeatureFlags.native-oss.js | 1 + .../forks/ReactFeatureFlags.test-renderer.js | 1 + .../ReactFeatureFlags.test-renderer.native.js | 1 + .../ReactFeatureFlags.test-renderer.www.js | 1 + .../forks/ReactFeatureFlags.www-dynamic.js | 1 + .../shared/forks/ReactFeatureFlags.www.js | 1 + packages/shared/getComponentNameFromType.js | 32 +++- packages/shared/isValidElementType.js | 7 +- 33 files changed, 400 insertions(+), 473 deletions(-) diff --git a/packages/react-client/src/ReactFlightReplyClient.js b/packages/react-client/src/ReactFlightReplyClient.js index 31e3a3f17dda8..650980cc2c1e3 100644 --- a/packages/react-client/src/ReactFlightReplyClient.js +++ b/packages/react-client/src/ReactFlightReplyClient.js @@ -14,10 +14,12 @@ import type { RejectedThenable, ReactCustomFormAction, } from 'shared/ReactTypes'; +import {enableRenderableContext} from 'shared/ReactFeatureFlags'; import { REACT_ELEMENT_TYPE, REACT_LAZY_TYPE, + REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE, getIteratorFn, } from 'shared/ReactSymbols'; @@ -302,7 +304,10 @@ export function processReply( 'React Lazy cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key), ); - } else if ((value: any).$$typeof === REACT_PROVIDER_TYPE) { + } else if ( + (value: any).$$typeof === + (enableRenderableContext ? REACT_CONTEXT_TYPE : REACT_PROVIDER_TYPE) + ) { console.error( 'React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key), diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js index 962d7d8bba2b5..103cfa08f0ab0 100644 --- a/packages/react-debug-tools/src/ReactDebugHooks.js +++ b/packages/react-debug-tools/src/ReactDebugHooks.js @@ -10,7 +10,6 @@ import type { Awaited, ReactContext, - ReactProviderType, StartTransitionOptions, Usable, Thenable, @@ -931,8 +930,11 @@ function setupContexts(contextMap: Map, any>, fiber: Fiber) { let current: null | Fiber = fiber; while (current) { if (current.tag === ContextProvider) { - const providerType: ReactProviderType = current.type; - const context: ReactContext = providerType._context; + let context: ReactContext = current.type; + if ((context: any)._context !== undefined) { + // Support inspection of pre-19+ providers. + context = (context: any)._context; + } if (!contextMap.has(context)) { // Store the current value that we're going to restore later. contextMap.set(context, context._currentValue); diff --git a/packages/react-devtools-shared/src/backend/ReactSymbols.js b/packages/react-devtools-shared/src/backend/ReactSymbols.js index 64f84cc913705..2a79ce83ae0a4 100644 --- a/packages/react-devtools-shared/src/backend/ReactSymbols.js +++ b/packages/react-devtools-shared/src/backend/ReactSymbols.js @@ -51,6 +51,8 @@ export const PROFILER_SYMBOL_STRING = 'Symbol(react.profiler)'; export const PROVIDER_NUMBER = 0xeacd; export const PROVIDER_SYMBOL_STRING = 'Symbol(react.provider)'; +export const CONSUMER_SYMBOL_STRING = 'Symbol(react.consumer)'; + export const SCOPE_NUMBER = 0xead7; export const SCOPE_SYMBOL_STRING = 'Symbol(react.scope)'; diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index 069cde215a1ca..59b2059dc8a61 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -79,6 +79,7 @@ import { PROVIDER_SYMBOL_STRING, CONTEXT_NUMBER, CONTEXT_SYMBOL_STRING, + CONSUMER_SYMBOL_STRING, STRICT_MODE_NUMBER, STRICT_MODE_SYMBOL_STRING, PROFILER_NUMBER, @@ -525,6 +526,15 @@ export function getInternalReactConstants(version: string): { case CONTEXT_NUMBER: case CONTEXT_SYMBOL_STRING: case SERVER_CONTEXT_SYMBOL_STRING: + if ( + fiber.type._context === undefined && + fiber.type.Provider === fiber.type + ) { + // In 19+, Context.Provider === Context, so this is a provider. + resolvedContext = fiber.type; + return `${resolvedContext.displayName || 'Context'}.Provider`; + } + // 16.3-16.5 read from "type" because the Consumer is the actual context object. // 16.6+ should read from "type._context" because Consumer can be different (in DEV). // NOTE Keep in sync with inspectElementRaw() @@ -533,6 +543,10 @@ export function getInternalReactConstants(version: string): { // NOTE: TraceUpdatesBackendManager depends on the name ending in '.Consumer' // If you change the name, figure out a more resilient way to detect it. return `${resolvedContext.displayName || 'Context'}.Consumer`; + case CONSUMER_SYMBOL_STRING: + // 19+ + resolvedContext = fiber.type._context; + return `${resolvedContext.displayName || 'Context'}.Consumer`; case STRICT_MODE_NUMBER: case STRICT_MODE_SYMBOL_STRING: return null; @@ -3178,8 +3192,14 @@ export function attach( } } } else if ( - typeSymbol === CONTEXT_NUMBER || - typeSymbol === CONTEXT_SYMBOL_STRING + // Detect pre-19 Context Consumers + (typeSymbol === CONTEXT_NUMBER || typeSymbol === CONTEXT_SYMBOL_STRING) && + !( + // In 19+, CONTEXT_SYMBOL_STRING means a Provider instead. + // It will be handled in a different branch below. + // Eventually, this entire branch can be removed. + (type._context === undefined && type.Provider === type) + ) ) { // 16.3-16.5 read from "type" because the Consumer is the actual context object. // 16.6+ should read from "type._context" because Consumer can be different (in DEV). @@ -3209,6 +3229,35 @@ export function attach( } } + current = current.return; + } + } else if ( + // Detect 19+ Context Consumers + typeSymbol === CONSUMER_SYMBOL_STRING + ) { + // This branch is 19+ only, where Context.Provider === Context. + // NOTE Keep in sync with getDisplayNameForFiber() + const consumerResolvedContext = type._context; + + // Global context value. + context = consumerResolvedContext._currentValue || null; + + // Look for overridden value. + let current = ((fiber: any): Fiber).return; + while (current !== null) { + const currentType = current.type; + const currentTypeSymbol = getTypeSymbol(currentType); + if ( + // In 19+, these are Context Providers + currentTypeSymbol === CONTEXT_SYMBOL_STRING + ) { + const providerResolvedContext = currentType; + if (providerResolvedContext === consumerResolvedContext) { + context = current.memoizedProps.value; + break; + } + } + current = current.return; } } diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js index 718dc983cb371..a460e2104ce88 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js @@ -31,8 +31,7 @@ function initModules() { }; } -const {resetModules, itRenders, clientRenderOnBadMarkup} = - ReactDOMServerIntegrationUtils(initModules); +const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules); describe('ReactDOMServerIntegration', () => { beforeEach(() => { @@ -296,115 +295,35 @@ describe('ReactDOMServerIntegration', () => { expect(e.querySelector('#language3').textContent).toBe('french'); }); - itRenders( - 'should warn with an error message when using Context as consumer in DEV', - async render => { - const Theme = React.createContext('dark'); - const Language = React.createContext('french'); + itRenders('should treat Context as Context.Provider', async render => { + // The `itRenders` helpers don't work with the gate pragma, so we have to do + // this instead. + if (gate(flags => !flags.enableRenderableContext)) { + return; + } - const App = () => ( -
- - - - {theme =>
{theme}
}
-
-
-
-
- ); - // We expect 1 error. - await render(, 1); - }, - ); - - // False positive regression test. - itRenders( - 'should not warn when using Consumer from React < 16.6 with newer renderer', - async render => { - const Theme = React.createContext('dark'); - const Language = React.createContext('french'); - // React 16.5 and earlier didn't have a separate object. - Theme.Consumer = Theme; - - const App = () => ( -
- - - - {theme =>
{theme}
}
-
-
-
-
- ); - // We expect 0 errors. - await render(, 0); - }, - ); - - itRenders( - 'should warn with an error message when using nested context consumers in DEV', - async render => { - const App = () => { - const Theme = React.createContext('dark'); - const Language = React.createContext('french'); + const Theme = React.createContext('dark'); + const Language = React.createContext('french'); - return ( -
- - - - - {theme =>
{theme}
} -
-
-
-
-
- ); - }; - await render( - , - render === clientRenderOnBadMarkup - ? // On hydration mismatch we retry and therefore log the warning again. - 2 - : 1, - ); - }, - ); + expect(Theme.Provider).toBe(Theme); - itRenders( - 'should warn with an error message when using Context.Consumer.Provider DEV', - async render => { - const App = () => { - const Theme = React.createContext('dark'); - const Language = React.createContext('french'); + const App = () => ( +
+ + + + + {theme =>
{theme}
} +
+
+
+
+
+ ); - return ( -
- - - - - {theme =>
{theme}
} -
-
-
-
-
- ); - }; - - await render( - , - render === clientRenderOnBadMarkup - ? // On hydration mismatch we retry and therefore log the warning again. - 2 - : 1, - ); - }, - ); + const e = await render(, 0); + expect(e.textContent).toBe('dark'); + }); it('does not pollute parallel node streams', () => { const LoggedInUser = React.createContext(); diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js index c2c89c8093499..b95c20f9e3182 100644 --- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js @@ -1000,22 +1000,15 @@ describe('ReactDOMServer', () => { ]); }); + // @gate enableRenderableContext || !__DEV__ it('should warn if an invalid contextType is defined', () => { const Context = React.createContext(); - class ComponentA extends React.Component { - // It should warn for both Context.Consumer and Context.Provider static contextType = Context.Consumer; render() { return
; } } - class ComponentB extends React.Component { - static contextType = Context.Provider; - render() { - return
; - } - } expect(() => { ReactDOMServer.renderToString(); @@ -1028,13 +1021,14 @@ describe('ReactDOMServer', () => { // Warnings should be deduped by component type ReactDOMServer.renderToString(); - expect(() => { - ReactDOMServer.renderToString(); - }).toErrorDev( - 'Warning: ComponentB defines an invalid contextType. ' + - 'contextType should point to the Context object returned by React.createContext(). ' + - 'Did you accidentally pass the Context.Provider instead?', - ); + class ComponentB extends React.Component { + static contextType = Context.Provider; + render() { + return
; + } + } + // Does not warn because Context === Context.Provider. + ReactDOMServer.renderToString(); }); it('should not warn when class contextType is null', () => { diff --git a/packages/react-is/src/ReactIs.js b/packages/react-is/src/ReactIs.js index 41a63d6407bea..6e935bd8f7c64 100644 --- a/packages/react-is/src/ReactIs.js +++ b/packages/react-is/src/ReactIs.js @@ -19,11 +19,13 @@ import { REACT_PORTAL_TYPE, REACT_PROFILER_TYPE, REACT_PROVIDER_TYPE, + REACT_CONSUMER_TYPE, REACT_STRICT_MODE_TYPE, REACT_SUSPENSE_TYPE, REACT_SUSPENSE_LIST_TYPE, } from 'shared/ReactSymbols'; import isValidElementType from 'shared/isValidElementType'; +import {enableRenderableContext} from 'shared/ReactFeatureFlags'; export function typeOf(object: any): mixed { if (typeof object === 'object' && object !== null) { @@ -47,8 +49,17 @@ export function typeOf(object: any): mixed { case REACT_FORWARD_REF_TYPE: case REACT_LAZY_TYPE: case REACT_MEMO_TYPE: - case REACT_PROVIDER_TYPE: return $$typeofType; + case REACT_CONSUMER_TYPE: + if (enableRenderableContext) { + return $$typeofType; + } + // Fall through + case REACT_PROVIDER_TYPE: + if (!enableRenderableContext) { + return $$typeofType; + } + // Fall through default: return $$typeof; } @@ -61,8 +72,12 @@ export function typeOf(object: any): mixed { return undefined; } -export const ContextConsumer = REACT_CONTEXT_TYPE; -export const ContextProvider = REACT_PROVIDER_TYPE; +export const ContextConsumer: symbol = enableRenderableContext + ? REACT_CONSUMER_TYPE + : REACT_CONTEXT_TYPE; +export const ContextProvider: symbol = enableRenderableContext + ? REACT_CONTEXT_TYPE + : REACT_PROVIDER_TYPE; export const Element = REACT_ELEMENT_TYPE; export const ForwardRef = REACT_FORWARD_REF_TYPE; export const Fragment = REACT_FRAGMENT_TYPE; @@ -77,10 +92,18 @@ export const SuspenseList = REACT_SUSPENSE_LIST_TYPE; export {isValidElementType}; export function isContextConsumer(object: any): boolean { - return typeOf(object) === REACT_CONTEXT_TYPE; + if (enableRenderableContext) { + return typeOf(object) === REACT_CONSUMER_TYPE; + } else { + return typeOf(object) === REACT_CONTEXT_TYPE; + } } export function isContextProvider(object: any): boolean { - return typeOf(object) === REACT_PROVIDER_TYPE; + if (enableRenderableContext) { + return typeOf(object) === REACT_CONTEXT_TYPE; + } else { + return typeOf(object) === REACT_PROVIDER_TYPE; + } } export function isElement(object: any): boolean { return ( diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 82a07c2bbcf24..982e8b5905456 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -38,6 +38,7 @@ import { enableDebugTracing, enableFloat, enableDO_NOT_USE_disableStrictPassiveEffect, + enableRenderableContext, } from 'shared/ReactFeatureFlags'; import {NoFlags, Placement, StaticMask} from './ReactFiberFlags'; import {ConcurrentRoot} from './ReactRootTags'; @@ -96,6 +97,7 @@ import { REACT_PROFILER_TYPE, REACT_PROVIDER_TYPE, REACT_CONTEXT_TYPE, + REACT_CONSUMER_TYPE, REACT_SUSPENSE_TYPE, REACT_SUSPENSE_LIST_TYPE, REACT_MEMO_TYPE, @@ -580,12 +582,25 @@ export function createFiberFromTypeAndProps( if (typeof type === 'object' && type !== null) { switch (type.$$typeof) { case REACT_PROVIDER_TYPE: - fiberTag = ContextProvider; - break getTag; + if (!enableRenderableContext) { + fiberTag = ContextProvider; + break getTag; + } + // Fall through case REACT_CONTEXT_TYPE: - // This is a consumer - fiberTag = ContextConsumer; - break getTag; + if (enableRenderableContext) { + fiberTag = ContextProvider; + break getTag; + } else { + fiberTag = ContextConsumer; + break getTag; + } + case REACT_CONSUMER_TYPE: + if (enableRenderableContext) { + fiberTag = ContextConsumer; + break getTag; + } + // Fall through case REACT_FORWARD_REF_TYPE: fiberTag = ForwardRef; if (__DEV__) { diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 3bd5253e71d02..ab05fc4eb7f05 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -8,7 +8,7 @@ */ import type { - ReactProviderType, + ReactConsumerType, ReactContext, ReactNodeList, } from 'shared/ReactTypes'; @@ -110,6 +110,7 @@ import { enableFormActions, enableAsyncActions, enablePostpone, + enableRenderableContext, } from 'shared/ReactFeatureFlags'; import isArray from 'shared/isArray'; import shallowEqual from 'shared/shallowEqual'; @@ -3528,9 +3529,12 @@ function updateContextProvider( workInProgress: Fiber, renderLanes: Lanes, ) { - const providerType: ReactProviderType = workInProgress.type; - const context: ReactContext = providerType._context; - + let context: ReactContext; + if (enableRenderableContext) { + context = workInProgress.type; + } else { + context = workInProgress.type._context; + } const newProps = workInProgress.pendingProps; const oldProps = workInProgress.memoizedProps; @@ -3587,37 +3591,21 @@ function updateContextProvider( return workInProgress.child; } -let hasWarnedAboutUsingContextAsConsumer = false; - function updateContextConsumer( current: Fiber | null, workInProgress: Fiber, renderLanes: Lanes, ) { - let context: ReactContext = workInProgress.type; - // The logic below for Context differs depending on PROD or DEV mode. In - // DEV mode, we create a separate object for Context.Consumer that acts - // like a proxy to Context. This proxy object adds unnecessary code in PROD - // so we use the old behaviour (Context.Consumer references Context) to - // reduce size and overhead. The separate object references context via - // a property called "_context", which also gives us the ability to check - // in DEV mode if this property exists or not and warn if it does not. - if (__DEV__) { - if ((context: any)._context === undefined) { - // This may be because it's a Context (rather than a Consumer). - // Or it may be because it's older React where they're the same thing. - // We only want to warn if we're sure it's a new React. - if (context !== context.Consumer) { - if (!hasWarnedAboutUsingContextAsConsumer) { - hasWarnedAboutUsingContextAsConsumer = true; - console.error( - 'Rendering directly is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - } + let context: ReactContext; + if (enableRenderableContext) { + const consumerType: ReactConsumerType = workInProgress.type; + context = consumerType._context; + } else { + context = workInProgress.type; + if (__DEV__) { + if ((context: any)._context !== undefined) { + context = (context: any)._context; } - } else { - context = (context: any)._context; } } const newProps = workInProgress.pendingProps; @@ -3869,7 +3857,12 @@ function attemptEarlyBailoutIfNoScheduledUpdate( break; case ContextProvider: { const newValue = workInProgress.memoizedProps.value; - const context: ReactContext = workInProgress.type._context; + let context: ReactContext; + if (enableRenderableContext) { + context = workInProgress.type; + } else { + context = workInProgress.type._context; + } pushProvider(workInProgress, context, newValue); break; } diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.js b/packages/react-reconciler/src/ReactFiberClassComponent.js index cceb78c8ed878..a38c859d804ab 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.js @@ -32,7 +32,7 @@ import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFrom import getComponentNameFromType from 'shared/getComponentNameFromType'; import assign from 'shared/assign'; import isArray from 'shared/isArray'; -import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols'; +import {REACT_CONTEXT_TYPE, REACT_CONSUMER_TYPE} from 'shared/ReactSymbols'; import {resolveDefaultProps} from './ReactFiberLazyComponent'; import { @@ -596,8 +596,7 @@ function constructClassInstance( // Allow null for conditional declaration contextType === null || (contextType !== undefined && - contextType.$$typeof === REACT_CONTEXT_TYPE && - contextType._context === undefined); // Not a + contextType.$$typeof === REACT_CONTEXT_TYPE); if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) { didWarnAboutInvalidateContextType.add(ctor); @@ -611,10 +610,7 @@ function constructClassInstance( 'try moving the createContext() call to a separate file.'; } else if (typeof contextType !== 'object') { addendum = ' However, it is set to a ' + typeof contextType + '.'; - } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) { - addendum = ' Did you accidentally pass the Context.Provider instead?'; - } else if (contextType._context !== undefined) { - // + } else if (contextType.$$typeof === REACT_CONSUMER_TYPE) { addendum = ' Did you accidentally pass the Context.Consumer instead?'; } else { addendum = diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.js b/packages/react-reconciler/src/ReactFiberCompleteWork.js index 78dd30cd5f325..639cec6cbf0d5 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.js @@ -39,6 +39,7 @@ import { enableCache, enableTransitionTracing, enableFloat, + enableRenderableContext, passChildrenWhenCloningPersistedNodes, } from 'shared/ReactFeatureFlags'; @@ -1505,7 +1506,12 @@ function completeWork( return null; case ContextProvider: // Pop provider fiber - const context: ReactContext = workInProgress.type._context; + let context: ReactContext; + if (enableRenderableContext) { + context = workInProgress.type; + } else { + context = workInProgress.type._context; + } popProvider(context, workInProgress); bubbleProperties(workInProgress); return null; diff --git a/packages/react-reconciler/src/ReactFiberNewContext.js b/packages/react-reconciler/src/ReactFiberNewContext.js index 0aec54348c2cd..5d9b165635a1e 100644 --- a/packages/react-reconciler/src/ReactFiberNewContext.js +++ b/packages/react-reconciler/src/ReactFiberNewContext.js @@ -7,7 +7,7 @@ * @flow */ -import type {ReactContext, ReactProviderType} from 'shared/ReactTypes'; +import type {ReactContext} from 'shared/ReactTypes'; import type { Fiber, ContextDependency, @@ -46,6 +46,7 @@ import { enableLazyContextPropagation, enableFormActions, enableAsyncActions, + enableRenderableContext, } from 'shared/ReactFeatureFlags'; import { getHostTransitionProvider, @@ -561,8 +562,12 @@ function propagateParentContextChanges( const oldProps = currentParent.memoizedProps; if (oldProps !== null) { - const providerType: ReactProviderType = parent.type; - const context: ReactContext = providerType._context; + let context: ReactContext; + if (enableRenderableContext) { + context = parent.type; + } else { + context = parent.type._context; + } const newProps = parent.pendingProps; const newValue = newProps.value; diff --git a/packages/react-reconciler/src/ReactFiberScope.js b/packages/react-reconciler/src/ReactFiberScope.js index a95518aacb31c..0cb1c62ba8d02 100644 --- a/packages/react-reconciler/src/ReactFiberScope.js +++ b/packages/react-reconciler/src/ReactFiberScope.js @@ -22,7 +22,10 @@ import { import {isFiberSuspenseAndTimedOut} from './ReactFiberTreeReflection'; import {HostComponent, ScopeComponent, ContextProvider} from './ReactWorkTags'; -import {enableScopeAPI} from 'shared/ReactFeatureFlags'; +import { + enableScopeAPI, + enableRenderableContext, +} from 'shared/ReactFeatureFlags'; function getSuspenseFallbackChild(fiber: Fiber): Fiber | null { return ((((fiber.child: any): Fiber).sibling: any): Fiber).child; @@ -113,7 +116,10 @@ function collectNearestContextValues( context: ReactContext, childContextValues: Array, ): void { - if (node.tag === ContextProvider && node.type._context === context) { + if ( + node.tag === ContextProvider && + (enableRenderableContext ? node.type : node.type._context) === context + ) { const contextValue = node.memoizedProps.value; childContextValues.push(contextValue); } else { diff --git a/packages/react-reconciler/src/ReactFiberUnwindWork.js b/packages/react-reconciler/src/ReactFiberUnwindWork.js index fdbd3357ed3c3..cc77647cb8556 100644 --- a/packages/react-reconciler/src/ReactFiberUnwindWork.js +++ b/packages/react-reconciler/src/ReactFiberUnwindWork.js @@ -35,6 +35,7 @@ import { enableProfilerTimer, enableCache, enableTransitionTracing, + enableRenderableContext, } from 'shared/ReactFeatureFlags'; import {popHostContainer, popHostContext} from './ReactFiberHostContext'; @@ -160,7 +161,12 @@ function unwindWork( popHostContainer(workInProgress); return null; case ContextProvider: - const context: ReactContext = workInProgress.type._context; + let context: ReactContext; + if (enableRenderableContext) { + context = workInProgress.type; + } else { + context = workInProgress.type._context; + } popProvider(context, workInProgress); return null; case OffscreenComponent: @@ -250,7 +256,12 @@ function unwindInterruptedWork( popSuspenseListContext(interruptedWork); break; case ContextProvider: - const context: ReactContext = interruptedWork.type._context; + let context: ReactContext; + if (enableRenderableContext) { + context = interruptedWork.type; + } else { + context = interruptedWork.type._context; + } popProvider(context, interruptedWork); break; case OffscreenComponent: diff --git a/packages/react-reconciler/src/__tests__/ReactNewContext-test.js b/packages/react-reconciler/src/__tests__/ReactNewContext-test.js index ad5eba5150ee0..a6cabd6c641f7 100644 --- a/packages/react-reconciler/src/__tests__/ReactNewContext-test.js +++ b/packages/react-reconciler/src/__tests__/ReactNewContext-test.js @@ -1339,6 +1339,7 @@ describe('ReactNewContext', () => { ); }); + // @gate enableRenderableContext || !__DEV__ it('warns when passed a consumer', async () => { const Context = React.createContext(0); function Foo() { @@ -1346,21 +1347,7 @@ describe('ReactNewContext', () => { } ReactNoop.render(); await expect(async () => await waitForAll([])).toErrorDev( - 'Calling useContext(Context.Consumer) is not supported, may cause bugs, ' + - 'and will be removed in a future major release. ' + - 'Did you mean to call useContext(Context) instead?', - ); - }); - - it('warns when passed a provider', async () => { - const Context = React.createContext(0); - function Foo() { - useContext(Context.Provider); - return null; - } - ReactNoop.render(); - await expect(async () => await waitForAll([])).toErrorDev( - 'Calling useContext(Context.Provider) is not supported. ' + + 'Calling useContext(Context.Consumer) is not supported and will cause bugs. ' + 'Did you mean to call useContext(Context) instead?', ); }); @@ -1649,99 +1636,23 @@ Context fuzz tester error! Copy and paste the following line into the test suite }); }); - it('should warn with an error message when using context as a consumer in DEV', async () => { - const BarContext = React.createContext({value: 'bar-initial'}); - const BarConsumer = BarContext; - - function Component() { - return ( - <> - - - {({value}) =>
} - - - - ); - } - - await expect(async () => { - ReactNoop.render(); - await waitForAll([]); - }).toErrorDev( - 'Rendering directly is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - }); - - // False positive regression test. - it('should not warn when using Consumer from React < 16.6 with newer renderer', async () => { + // @gate enableRenderableContext + it('should treat Context as Context.Provider', async () => { const BarContext = React.createContext({value: 'bar-initial'}); - // React 16.5 and earlier didn't have a separate object. - BarContext.Consumer = BarContext; + expect(BarContext.Provider).toBe(BarContext); function Component() { return ( - <> - - - {({value}) =>
} - - - + + + {({value}) => } + + ); } ReactNoop.render(); await waitForAll([]); - }); - - it('should warn with an error message when using nested context consumers in DEV', async () => { - const BarContext = React.createContext({value: 'bar-initial'}); - const BarConsumer = BarContext; - - function Component() { - return ( - <> - - - {({value}) =>
} - - - - ); - } - - await expect(async () => { - ReactNoop.render(); - await waitForAll([]); - }).toErrorDev( - 'Rendering is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - }); - - it('should warn with an error message when using Context.Consumer.Provider DEV', async () => { - const BarContext = React.createContext({value: 'bar-initial'}); - - function Component() { - return ( - <> - - - {({value}) =>
} - - - - ); - } - - await expect(async () => { - ReactNoop.render(); - await waitForAll([]); - }).toErrorDev( - 'Rendering is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); + expect(ReactNoop).toMatchRenderedOutput(); }); }); diff --git a/packages/react-reconciler/src/getComponentNameFromFiber.js b/packages/react-reconciler/src/getComponentNameFromFiber.js index f8b2388da9073..1a8464835ce4f 100644 --- a/packages/react-reconciler/src/getComponentNameFromFiber.js +++ b/packages/react-reconciler/src/getComponentNameFromFiber.js @@ -7,10 +7,13 @@ * @flow */ -import type {ReactContext, ReactProviderType} from 'shared/ReactTypes'; +import type {ReactContext, ReactConsumerType} from 'shared/ReactTypes'; import type {Fiber} from './ReactInternalTypes'; -import {enableLegacyHidden} from 'shared/ReactFeatureFlags'; +import { + enableLegacyHidden, + enableRenderableContext, +} from 'shared/ReactFeatureFlags'; import { FunctionComponent, @@ -68,11 +71,21 @@ export default function getComponentNameFromFiber(fiber: Fiber): string | null { case CacheComponent: return 'Cache'; case ContextConsumer: - const context: ReactContext = (type: any); - return getContextName(context) + '.Consumer'; + if (enableRenderableContext) { + const consumer: ReactConsumerType = (type: any); + return getContextName(consumer._context) + '.Consumer'; + } else { + const context: ReactContext = (type: any); + return getContextName(context) + '.Consumer'; + } case ContextProvider: - const provider: ReactProviderType = (type: any); - return getContextName(provider._context) + '.Provider'; + if (enableRenderableContext) { + const context: ReactContext = (type: any); + return getContextName(context) + '.Provider'; + } else { + const provider = (type: any); + return getContextName(provider._context) + '.Provider'; + } case DehydratedFragment: return 'DehydratedFragment'; case ForwardRef: diff --git a/packages/react-server/src/ReactFizzClassComponent.js b/packages/react-server/src/ReactFizzClassComponent.js index e624dfa941293..7d528348d6c88 100644 --- a/packages/react-server/src/ReactFizzClassComponent.js +++ b/packages/react-server/src/ReactFizzClassComponent.js @@ -13,7 +13,7 @@ import {readContext} from './ReactFizzNewContext'; import {disableLegacyContext} from 'shared/ReactFeatureFlags'; import {get as getInstance, set as setInstance} from 'shared/ReactInstanceMap'; import getComponentNameFromType from 'shared/getComponentNameFromType'; -import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols'; +import {REACT_CONTEXT_TYPE, REACT_CONSUMER_TYPE} from 'shared/ReactSymbols'; import assign from 'shared/assign'; import isArray from 'shared/isArray'; @@ -181,8 +181,7 @@ export function constructClassInstance( // Allow null for conditional declaration contextType === null || (contextType !== undefined && - contextType.$$typeof === REACT_CONTEXT_TYPE && - contextType._context === undefined); // Not a + contextType.$$typeof === REACT_CONTEXT_TYPE); if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) { didWarnAboutInvalidateContextType.add(ctor); @@ -196,10 +195,7 @@ export function constructClassInstance( 'try moving the createContext() call to a separate file.'; } else if (typeof contextType !== 'object') { addendum = ' However, it is set to a ' + typeof contextType + '.'; - } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) { - addendum = ' Did you accidentally pass the Context.Provider instead?'; - } else if (contextType._context !== undefined) { - // + } else if (contextType.$$typeof === REACT_CONSUMER_TYPE) { addendum = ' Did you accidentally pass the Context.Consumer instead?'; } else { addendum = diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index dee3fe5bfcfff..a928b2651a934 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -15,7 +15,7 @@ import type { import type { ReactNodeList, ReactContext, - ReactProviderType, + ReactConsumerType, OffscreenMode, Wakeable, Thenable, @@ -32,6 +32,7 @@ import type {ContextSnapshot} from './ReactFizzNewContext'; import type {ComponentStackNode} from './ReactFizzComponentStack'; import type {TreeContext} from './ReactFizzTreeContext'; import type {ThenableState} from './ReactFizzThenable'; +import {enableRenderableContext} from 'shared/ReactFeatureFlags'; import { scheduleWork, @@ -129,6 +130,7 @@ import { REACT_MEMO_TYPE, REACT_PROVIDER_TYPE, REACT_CONTEXT_TYPE, + REACT_CONSUMER_TYPE, REACT_SCOPE_TYPE, REACT_OFFSCREEN_TYPE, REACT_POSTPONE_TYPE, @@ -1393,7 +1395,6 @@ let didWarnAboutReassigningProps = false; const didWarnAboutDefaultPropsOnFunctionComponent: {[string]: boolean} = {}; let didWarnAboutGenerators = false; let didWarnAboutMaps = false; -let hasWarnedAboutUsingContextAsConsumer = false; // This would typically be a function component but we still support module pattern // components for some reason. @@ -1703,31 +1704,6 @@ function renderContextConsumer( context: ReactContext, props: Object, ): void { - // The logic below for Context differs depending on PROD or DEV mode. In - // DEV mode, we create a separate object for Context.Consumer that acts - // like a proxy to Context. This proxy object adds unnecessary code in PROD - // so we use the old behaviour (Context.Consumer references Context) to - // reduce size and overhead. The separate object references context via - // a property called "_context", which also gives us the ability to check - // in DEV mode if this property exists or not and warn if it does not. - if (__DEV__) { - if ((context: any)._context === undefined) { - // This may be because it's a Context (rather than a Consumer). - // Or it may be because it's older React where they're the same thing. - // We only want to warn if we're sure it's a new React. - if (context !== context.Consumer) { - if (!hasWarnedAboutUsingContextAsConsumer) { - hasWarnedAboutUsingContextAsConsumer = true; - console.error( - 'Rendering directly is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - } - } - } else { - context = (context: any)._context; - } - } const render = props.children; if (__DEV__) { @@ -1754,10 +1730,9 @@ function renderContextProvider( request: Request, task: Task, keyPath: KeyNode, - type: ReactProviderType, + context: ReactContext, props: Object, ): void { - const context = type._context; const value = props.value; const children = props.children; let prevSnapshot; @@ -1909,12 +1884,37 @@ function renderElement( return; } case REACT_PROVIDER_TYPE: { - renderContextProvider(request, task, keyPath, type, props); - return; + if (!enableRenderableContext) { + const context: ReactContext = (type: any)._context; + renderContextProvider(request, task, keyPath, context, props); + return; + } + // Fall through } case REACT_CONTEXT_TYPE: { - renderContextConsumer(request, task, keyPath, type, props); - return; + if (enableRenderableContext) { + const context = type; + renderContextProvider(request, task, keyPath, context, props); + return; + } else { + let context: ReactContext = (type: any); + if (__DEV__) { + if ((context: any)._context !== undefined) { + context = (context: any)._context; + } + } + renderContextConsumer(request, task, keyPath, context, props); + return; + } + } + case REACT_CONSUMER_TYPE: { + if (enableRenderableContext) { + const context: ReactContext = (type: ReactConsumerType) + ._context; + renderContextConsumer(request, task, keyPath, context, props); + return; + } + // Fall through } case REACT_LAZY_TYPE: { renderLazyComponent(request, task, keyPath, type, props); diff --git a/packages/react/src/ReactContext.js b/packages/react/src/ReactContext.js index 90e73ec46d065..24461ebfbb7bf 100644 --- a/packages/react/src/ReactContext.js +++ b/packages/react/src/ReactContext.js @@ -7,10 +7,14 @@ * @flow */ -import {REACT_PROVIDER_TYPE, REACT_CONTEXT_TYPE} from 'shared/ReactSymbols'; +import { + REACT_PROVIDER_TYPE, + REACT_CONSUMER_TYPE, + REACT_CONTEXT_TYPE, +} from 'shared/ReactSymbols'; -import type {ReactProviderType} from 'shared/ReactTypes'; import type {ReactContext} from 'shared/ReactTypes'; +import {enableRenderableContext} from 'shared/ReactFeatureFlags'; export function createContext(defaultValue: T): ReactContext { // TODO: Second argument used to be an optional `calculateChangedBits` @@ -33,96 +37,71 @@ export function createContext(defaultValue: T): ReactContext { Consumer: (null: any), }; - context.Provider = { - $$typeof: REACT_PROVIDER_TYPE, - _context: context, - }; - - let hasWarnedAboutUsingNestedContextConsumers = false; - let hasWarnedAboutUsingConsumerProvider = false; - let hasWarnedAboutDisplayNameOnConsumer = false; - - if (__DEV__) { - // A separate object, but proxies back to the original context object for - // backwards compatibility. It has a different $$typeof, so we can properly - // warn for the incorrect usage of Context as a Consumer. - const Consumer = { - $$typeof: REACT_CONTEXT_TYPE, + if (enableRenderableContext) { + context.Provider = context; + context.Consumer = { + $$typeof: REACT_CONSUMER_TYPE, _context: context, }; - // $FlowFixMe[prop-missing]: Flow complains about not setting a value, which is intentional here - Object.defineProperties(Consumer, { - Provider: { - get() { - if (!hasWarnedAboutUsingConsumerProvider) { - hasWarnedAboutUsingConsumerProvider = true; - console.error( - 'Rendering is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - } - return context.Provider; - }, - set(_Provider: ReactProviderType) { - context.Provider = _Provider; - }, - }, - _currentValue: { - get() { - return context._currentValue; - }, - set(_currentValue: T) { - context._currentValue = _currentValue; - }, - }, - _currentValue2: { - get() { - return context._currentValue2; - }, - set(_currentValue2: T) { - context._currentValue2 = _currentValue2; + } else { + (context: any).Provider = { + $$typeof: REACT_PROVIDER_TYPE, + _context: context, + }; + if (__DEV__) { + const Consumer: any = { + $$typeof: REACT_CONTEXT_TYPE, + _context: context, + }; + Object.defineProperties(Consumer, { + Provider: { + get() { + return context.Provider; + }, + set(_Provider: any) { + context.Provider = _Provider; + }, }, - }, - _threadCount: { - get() { - return context._threadCount; + _currentValue: { + get() { + return context._currentValue; + }, + set(_currentValue: T) { + context._currentValue = _currentValue; + }, }, - set(_threadCount: number) { - context._threadCount = _threadCount; + _currentValue2: { + get() { + return context._currentValue2; + }, + set(_currentValue2: T) { + context._currentValue2 = _currentValue2; + }, }, - }, - Consumer: { - get() { - if (!hasWarnedAboutUsingNestedContextConsumers) { - hasWarnedAboutUsingNestedContextConsumers = true; - console.error( - 'Rendering is not supported and will be removed in ' + - 'a future major release. Did you mean to render instead?', - ); - } - return context.Consumer; + _threadCount: { + get() { + return context._threadCount; + }, + set(_threadCount: number) { + context._threadCount = _threadCount; + }, }, - }, - displayName: { - get() { - return context.displayName; + Consumer: { + get() { + return context.Consumer; + }, }, - set(displayName: void | string) { - if (!hasWarnedAboutDisplayNameOnConsumer) { - console.warn( - 'Setting `displayName` on Context.Consumer has no effect. ' + - "You should set it directly on the context with Context.displayName = '%s'.", - displayName, - ); - hasWarnedAboutDisplayNameOnConsumer = true; - } + displayName: { + get() { + return context.displayName; + }, + set(displayName: void | string) {}, }, - }, - }); - // $FlowFixMe[prop-missing]: Flow complains about missing properties because it doesn't understand defineProperty - context.Consumer = Consumer; - } else { - context.Consumer = context; + }); + (context: any).Consumer = Consumer; + } else { + (context: any).Consumer = context; + } } if (__DEV__) { diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index a2141cbc5dfbe..3d67608c87d75 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -13,6 +13,7 @@ import type { StartTransitionOptions, Usable, } from 'shared/ReactTypes'; +import {REACT_CONSUMER_TYPE} from 'shared/ReactSymbols'; import ReactCurrentDispatcher from './ReactCurrentDispatcher'; import ReactCurrentCache from './ReactCurrentCache'; @@ -72,22 +73,11 @@ export function getCacheForType(resourceType: () => T): T { export function useContext(Context: ReactContext): T { const dispatcher = resolveDispatcher(); if (__DEV__) { - // TODO: add a more generic warning for invalid values. - if ((Context: any)._context !== undefined) { - const realContext = (Context: any)._context; - // Don't deduplicate because this legitimately causes bugs - // and nobody should be using this in existing code. - if (realContext.Consumer === Context) { - console.error( - 'Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + - 'removed in a future major release. Did you mean to call useContext(Context) instead?', - ); - } else if (realContext.Provider === Context) { - console.error( - 'Calling useContext(Context.Provider) is not supported. ' + - 'Did you mean to call useContext(Context) instead?', - ); - } + if (Context.$$typeof === REACT_CONSUMER_TYPE) { + console.error( + 'Calling useContext(Context.Consumer) is not supported and will cause bugs. ' + + 'Did you mean to call useContext(Context) instead?', + ); } } return dispatcher.useContext(Context); diff --git a/packages/react/src/__tests__/ReactContextValidator-test.js b/packages/react/src/__tests__/ReactContextValidator-test.js index 79f1957acc6f3..3f0fc6ad419ca 100644 --- a/packages/react/src/__tests__/ReactContextValidator-test.js +++ b/packages/react/src/__tests__/ReactContextValidator-test.js @@ -564,22 +564,15 @@ describe('ReactContextValidator', () => { ); }); + // @gate enableRenderableContext || !__DEV__ it('should warn if an invalid contextType is defined', () => { const Context = React.createContext(); - // This tests that both Context.Consumer and Context.Provider - // warn about invalid contextType. class ComponentA extends React.Component { static contextType = Context.Consumer; render() { return
; } } - class ComponentB extends React.Component { - static contextType = Context.Provider; - render() { - return
; - } - } expect(() => { ReactTestUtils.renderIntoDocument(); @@ -592,13 +585,14 @@ describe('ReactContextValidator', () => { // Warnings should be deduped by component type ReactTestUtils.renderIntoDocument(); - expect(() => { - ReactTestUtils.renderIntoDocument(); - }).toErrorDev( - 'Warning: ComponentB defines an invalid contextType. ' + - 'contextType should point to the Context object returned by React.createContext(). ' + - 'Did you accidentally pass the Context.Provider instead?', - ); + class ComponentB extends React.Component { + static contextType = Context.Provider; + render() { + return
; + } + } + // This doesn't warn since Context.Provider === Context now. + ReactTestUtils.renderIntoDocument(); }); it('should not warn when class contextType is null', () => { @@ -723,19 +717,4 @@ describe('ReactContextValidator', () => { ' in Validator (at **)', ); }); - - it('warns if displayName is set on the consumer type', () => { - const Context = React.createContext(null); - - expect(() => { - Context.Consumer.displayName = 'IgnoredName'; - }).toWarnDev( - 'Warning: Setting `displayName` on Context.Consumer has no effect. ' + - "You should set it directly on the context with Context.displayName = 'IgnoredName'.", - {withoutStack: true}, - ); - - // warning is deduped by Context so subsequent setting is fine - Context.Consumer.displayName = 'ADifferentName'; - }); }); diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 3d8a7cf563bc8..c2ffe2a652692 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -121,6 +121,8 @@ export const passChildrenWhenCloningPersistedNodes = false; export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__; +export const enableRenderableContext = false; + /** * Enables an expiration time for retry lanes to avoid starvation. */ diff --git a/packages/shared/ReactSymbols.js b/packages/shared/ReactSymbols.js index 133a84953ea63..6dca3476be945 100644 --- a/packages/shared/ReactSymbols.js +++ b/packages/shared/ReactSymbols.js @@ -17,7 +17,8 @@ export const REACT_PORTAL_TYPE: symbol = Symbol.for('react.portal'); export const REACT_FRAGMENT_TYPE: symbol = Symbol.for('react.fragment'); export const REACT_STRICT_MODE_TYPE: symbol = Symbol.for('react.strict_mode'); export const REACT_PROFILER_TYPE: symbol = Symbol.for('react.profiler'); -export const REACT_PROVIDER_TYPE: symbol = Symbol.for('react.provider'); +export const REACT_PROVIDER_TYPE: symbol = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext +export const REACT_CONSUMER_TYPE: symbol = Symbol.for('react.consumer'); export const REACT_CONTEXT_TYPE: symbol = Symbol.for('react.context'); export const REACT_FORWARD_REF_TYPE: symbol = Symbol.for('react.forward_ref'); export const REACT_SUSPENSE_TYPE: symbol = Symbol.for('react.suspense'); diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 107a6082f8e58..59f3362e0cf8c 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -25,7 +25,7 @@ export type ReactText = string | number; export type ReactProvider = { $$typeof: symbol | number, - type: ReactProviderType, + type: ReactContext, key: null | string, ref: null, props: { @@ -34,14 +34,14 @@ export type ReactProvider = { }, }; -export type ReactProviderType = { +export type ReactConsumerType = { $$typeof: symbol | number, _context: ReactContext, }; export type ReactConsumer = { $$typeof: symbol | number, - type: ReactContext, + type: ReactConsumerType, key: null | string, ref: null, props: { @@ -51,8 +51,8 @@ export type ReactConsumer = { export type ReactContext = { $$typeof: symbol | number, - Consumer: ReactContext, - Provider: ReactProviderType, + Consumer: ReactConsumerType, + Provider: ReactContext, _currentValue: T, _currentValue2: T, _threadCount: number, diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 497a5b6bcf3a6..3990e11a2ac9b 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -66,6 +66,7 @@ export const enableComponentStackLocations = false; export const enableLegacyFBSupport = false; export const enableFilterEmptyStringAttributesDOM = true; export const enableGetInspectorDataForInstanceInProduction = true; +export const enableRenderableContext = false; export const enableRetryLaneExpiration = false; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 67b220974b517..d29f699abbbde 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -49,6 +49,7 @@ export const enableComponentStackLocations = false; export const enableLegacyFBSupport = false; export const enableFilterEmptyStringAttributesDOM = true; export const enableGetInspectorDataForInstanceInProduction = false; +export const enableRenderableContext = false; export const enableRetryLaneExpiration = false; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 63025e79fb18b..6577d2a338893 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -49,6 +49,7 @@ export const enableComponentStackLocations = true; export const enableLegacyFBSupport = false; export const enableFilterEmptyStringAttributesDOM = true; export const enableGetInspectorDataForInstanceInProduction = false; +export const enableRenderableContext = false; export const enableRetryLaneExpiration = false; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index 4baed7ddd2b07..fc53c654b16d9 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -51,6 +51,7 @@ export const enableUseEffectEventHook = false; export const enableClientRenderFallbackOnTextMismatch = true; export const enableUseRefAccessWarning = false; export const enableInfiniteRenderLoopDetection = false; +export const enableRenderableContext = false; export const enableRetryLaneExpiration = false; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 0105b2bed97c1..8e21c3b1a6286 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -49,6 +49,7 @@ export const enableComponentStackLocations = true; export const enableLegacyFBSupport = false; export const enableFilterEmptyStringAttributesDOM = true; export const enableGetInspectorDataForInstanceInProduction = false; +export const enableRenderableContext = false; export const enableRetryLaneExpiration = false; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js index 9b15bddded3fd..cd073c6429982 100644 --- a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js @@ -29,6 +29,7 @@ export const enableFormActions = __VARIANT__; export const alwaysThrottleRetries = __VARIANT__; export const enableDO_NOT_USE_disableStrictPassiveEffect = __VARIANT__; export const enableUseDeferredValueInitialArg = __VARIANT__; +export const enableRenderableContext = __VARIANT__; export const enableRetryLaneExpiration = __VARIANT__; export const retryLaneExpirationMs = 5000; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 3a3f0f86a6719..798134ab70c24 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -37,6 +37,7 @@ export const { syncLaneExpirationMs, transitionLaneExpirationMs, enableInfiniteRenderLoopDetection, + enableRenderableContext, } = dynamicFeatureFlags; // On WWW, __EXPERIMENTAL__ is used for a new modern build. diff --git a/packages/shared/getComponentNameFromType.js b/packages/shared/getComponentNameFromType.js index 310d4adc595dc..fb63ff465a6af 100644 --- a/packages/shared/getComponentNameFromType.js +++ b/packages/shared/getComponentNameFromType.js @@ -8,10 +8,11 @@ */ import type {LazyComponent} from 'react/src/ReactLazy'; -import type {ReactContext, ReactProviderType} from 'shared/ReactTypes'; +import type {ReactContext, ReactConsumerType} from 'shared/ReactTypes'; import { REACT_CONTEXT_TYPE, + REACT_CONSUMER_TYPE, REACT_FORWARD_REF_TYPE, REACT_FRAGMENT_TYPE, REACT_PORTAL_TYPE, @@ -26,7 +27,11 @@ import { REACT_TRACING_MARKER_TYPE, } from 'shared/ReactSymbols'; -import {enableTransitionTracing, enableCache} from './ReactFeatureFlags'; +import { + enableTransitionTracing, + enableCache, + enableRenderableContext, +} from './ReactFeatureFlags'; // Keep in sync with react-reconciler/getComponentNameFromFiber function getWrappedName( @@ -98,12 +103,27 @@ export default function getComponentNameFromType(type: mixed): string | null { } } switch (type.$$typeof) { + case REACT_PROVIDER_TYPE: + if (enableRenderableContext) { + return null; + } else { + const provider = (type: any); + return getContextName(provider._context) + '.Provider'; + } case REACT_CONTEXT_TYPE: const context: ReactContext = (type: any); - return getContextName(context) + '.Consumer'; - case REACT_PROVIDER_TYPE: - const provider: ReactProviderType = (type: any); - return getContextName(provider._context) + '.Provider'; + if (enableRenderableContext) { + return getContextName(context) + '.Provider'; + } else { + return getContextName(context) + '.Consumer'; + } + case REACT_CONSUMER_TYPE: + if (enableRenderableContext) { + const consumer: ReactConsumerType = (type: any); + return getContextName(consumer._context) + '.Consumer'; + } else { + return null; + } case REACT_FORWARD_REF_TYPE: return getWrappedName(type, type.render, 'ForwardRef'); case REACT_MEMO_TYPE: diff --git a/packages/shared/isValidElementType.js b/packages/shared/isValidElementType.js index 5b8511e084dba..aa2092a923dfc 100644 --- a/packages/shared/isValidElementType.js +++ b/packages/shared/isValidElementType.js @@ -9,10 +9,11 @@ import { REACT_CONTEXT_TYPE, + REACT_CONSUMER_TYPE, + REACT_PROVIDER_TYPE, REACT_FORWARD_REF_TYPE, REACT_FRAGMENT_TYPE, REACT_PROFILER_TYPE, - REACT_PROVIDER_TYPE, REACT_DEBUG_TRACING_MODE_TYPE, REACT_STRICT_MODE_TYPE, REACT_SUSPENSE_TYPE, @@ -31,6 +32,7 @@ import { enableTransitionTracing, enableDebugTracing, enableLegacyHidden, + enableRenderableContext, } from './ReactFeatureFlags'; const REACT_CLIENT_REFERENCE: symbol = Symbol.for('react.client.reference'); @@ -61,8 +63,9 @@ export default function isValidElementType(type: mixed): boolean { if ( type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || - type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || + (!enableRenderableContext && type.$$typeof === REACT_PROVIDER_TYPE) || + (enableRenderableContext && type.$$typeof === REACT_CONSUMER_TYPE) || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since From 015ff2ed66c1d164111752263682d1d757c97f3e Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 13 Feb 2024 11:39:45 -0500 Subject: [PATCH 2/6] Revert "[Tests] Reset modules by default" (#28318) This was causing a slowdown in one of the tests ESLintRuleExhaustiveDeps-test.js. Reverting until we figure out why. --- .../react-art/src/__tests__/ReactART-test.js | 35 +++-- .../src/__tests__/ReactFlight-test.js | 1 + .../ReactDevToolsHooksIntegration-test.js | 2 + .../__tests__/ReactHooksInspection-test.js | 1 + .../ReactHooksInspectionIntegration-test.js | 1 + .../src/__tests__/console-test.js | 2 + .../hooks/__tests__/parseHookNames-test.js | 2 + .../__tests__/DOMPropertyOperations-test.js | 1 + .../__tests__/InvalidEventListeners-test.js | 1 + .../ReactBrowserEventEmitter-test.js | 1 + .../__tests__/ReactChildReconciler-test.js | 2 + .../src/__tests__/ReactComponent-test.js | 2 + .../__tests__/ReactComponentLifeCycle-test.js | 2 + .../__tests__/ReactCompositeComponent-test.js | 1 + .../ReactCompositeComponentState-test.js | 124 +++++++++--------- .../react-dom/src/__tests__/ReactDOM-test.js | 1 + .../src/__tests__/ReactDOMAttribute-test.js | 1 + .../src/__tests__/ReactDOMComponent-test.js | 1 + .../ReactDOMConsoleErrorReporting-test.js | 1 + ...eactDOMConsoleErrorReportingLegacy-test.js | 1 + .../__tests__/ReactDOMEventListener-test.js | 1 + .../ReactDOMEventPropagation-test.js | 1 + .../src/__tests__/ReactDOMFiber-test.js | 1 + .../ReactDOMFizzDeferredValue-test.js | 1 + .../src/__tests__/ReactDOMFizzForm-test.js | 1 + .../src/__tests__/ReactDOMFizzServer-test.js | 1 + .../ReactDOMFizzServerBrowser-test.js | 1 + .../__tests__/ReactDOMFizzServerEdge-test.js | 1 + .../__tests__/ReactDOMFizzServerNode-test.js | 1 + .../ReactDOMFizzShellHydration-test.js | 1 + .../src/__tests__/ReactDOMFizzStatic-test.js | 1 + .../ReactDOMFizzStaticBrowser-test.js | 1 + .../__tests__/ReactDOMFizzStaticFloat-test.js | 1 + .../__tests__/ReactDOMFizzStaticNode-test.js | 1 + ...actDOMFizzSuppressHydrationWarning-test.js | 1 + .../src/__tests__/ReactDOMFloat-test.js | 1 + .../src/__tests__/ReactDOMForm-test.js | 1 + .../src/__tests__/ReactDOMHooks-test.js | 2 + .../__tests__/ReactDOMHydrationDiff-test.js | 1 + .../__tests__/ReactDOMInReactServer-test.js | 1 + .../src/__tests__/ReactDOMInput-test.js | 2 + .../__tests__/ReactDOMInvalidARIAHook-test.js | 1 + .../src/__tests__/ReactDOMLegacyFloat-test.js | 2 + .../ReactDOMNativeEventHeuristic-test.js | 1 + .../__tests__/ReactDOMNestedEvents-test.js | 1 + .../src/__tests__/ReactDOMOption-test.js | 1 + .../src/__tests__/ReactDOMRoot-test.js | 1 + .../ReactDOMSafariMicrotaskBug-test.js | 1 + .../src/__tests__/ReactDOMSelect-test.js | 1 + ...eactDOMServerIntegrationAttributes-test.js | 2 + .../ReactDOMServerIntegrationBasic-test.js | 2 + .../ReactDOMServerIntegrationCheckbox-test.js | 2 + ...MServerIntegrationClassContextType-test.js | 2 + .../ReactDOMServerIntegrationElements-test.js | 1 + .../ReactDOMServerIntegrationFragment-test.js | 2 + .../ReactDOMServerIntegrationHooks-test.js | 3 + .../ReactDOMServerIntegrationInput-test.js | 2 + ...tDOMServerIntegrationLegacyContext-test.js | 2 + .../ReactDOMServerIntegrationModes-test.js | 2 + ...eactDOMServerIntegrationNewContext-test.js | 2 + ...ctDOMServerIntegrationReconnecting-test.js | 6 + .../ReactDOMServerIntegrationRefs-test.js | 2 + .../ReactDOMServerIntegrationSelect-test.js | 2 + ...ctDOMServerIntegrationSpecialTypes-test.js | 2 + .../ReactDOMServerIntegrationTextarea-test.js | 2 + ...ctDOMServerIntegrationUntrustedURL-test.js | 2 + ...OMServerIntegrationUserInteraction-test.js | 2 + .../ReactDOMServerLifecycles-test.js | 2 + ...ctDOMShorthandCSSPropertyCollision-test.js | 2 + .../ReactDOMSingletonComponents-test.js | 1 + .../ReactDOMSuspensePlaceholder-test.js | 1 + .../__tests__/ReactDOMTestSelectors-test.js | 3 + .../src/__tests__/ReactDOMTextarea-test.js | 2 + .../ReactDOMserverIntegrationProgress-test.js | 2 + .../ReactDeprecationWarnings-test.js | 1 + .../src/__tests__/ReactEmptyComponent-test.js | 2 + .../__tests__/ReactEventIndependence-test.js | 2 + .../__tests__/ReactFunctionComponent-test.js | 1 + .../src/__tests__/ReactIdentity-test.js | 1 + .../ReactLegacyCompositeComponent-test.js | 1 + .../src/__tests__/ReactLegacyMount-test.js | 2 + .../__tests__/ReactLegacyRootWarnings-test.js | 1 + .../src/__tests__/ReactLegacyUpdates-test.js | 1 + .../src/__tests__/ReactMultiChild-test.js | 1 + .../ReactMultiChildReconcile-test.js | 4 + .../src/__tests__/ReactRenderDocument-test.js | 2 + .../__tests__/ReactServerRendering-test.js | 1 + .../ReactServerRenderingBrowser-test.js | 1 + .../ReactServerRenderingHydration-test.js | 1 + .../src/__tests__/ReactTestUtilsAct-test.js | 1 + ...ReactTestUtilsActUnmockedScheduler-test.js | 1 + .../src/__tests__/ReactUpdates-test.js | 1 + .../__tests__/escapeTextForBrowser-test.js | 1 + .../quoteAttributeValueForBrowser-test.js | 1 + .../src/__tests__/refs-destruction-test.js | 2 + packages/react-dom/src/__tests__/refs-test.js | 14 +- .../src/__tests__/refsLegacy-test.js | 1 + .../__tests__/SyntheticFocusEvent-test.js | 1 + .../__tests__/SyntheticMouseEvent-test.js | 1 + .../__tests__/ChangeEventPlugin-test.js | 1 + .../__tests__/EnterLeaveEventPlugin-test.js | 2 + .../__tests__/SimpleEventPlugin-test.js | 3 + .../react-is/src/__tests__/ReactIs-test.js | 2 + .../src/__tests__/Activity-test.js | 2 + .../src/__tests__/ActivityStrictMode-test.js | 1 + .../src/__tests__/ActivitySuspense-test.js | 2 + .../src/__tests__/ReactActWarnings-test.js | 1 + .../src/__tests__/ReactAsyncActions-test.js | 2 + .../src/__tests__/ReactCPUSuspense-test.js | 2 + .../src/__tests__/ReactCache-test.js | 2 + .../src/__tests__/ReactCacheElement-test.js | 2 + .../ReactClassSetStateCallback-test.js | 2 + .../ReactConcurrentErrorRecovery-test.js | 2 + .../__tests__/ReactContextPropagation-test.js | 2 + .../src/__tests__/ReactDeferredValue-test.js | 2 + .../src/__tests__/ReactEffectOrdering-test.js | 1 + .../src/__tests__/ReactExpiration-test.js | 3 + .../src/__tests__/ReactFlushSync-test.js | 2 + .../ReactFlushSyncNoAggregateError-test.js | 2 + .../src/__tests__/ReactFragment-test.js | 2 + .../ReactHooksWithNoopRenderer-test.js | 1 + .../src/__tests__/ReactIncremental-test.js | 2 + .../ReactIncrementalErrorLogging-test.js | 1 + .../ReactIncrementalErrorReplay-test.js | 1 + .../ReactIncrementalReflection-test.js | 2 + .../ReactIncrementalScheduling-test.js | 2 + .../ReactIncrementalSideEffects-test.js | 2 + .../__tests__/ReactIncrementalUpdates-test.js | 2 + .../ReactIncrementalUpdatesMinimalism-test.js | 1 + .../__tests__/ReactInterleavedUpdates-test.js | 2 + .../src/__tests__/ReactMemo-test.js | 2 + .../src/__tests__/ReactNewContext-test.js | 2 + .../src/__tests__/ReactPersistent-test.js | 2 + .../ReactPersistentUpdatesMinimalism-test.js | 1 + .../ReactSchedulerIntegration-test.js | 6 + .../ReactSubtreeFlagsWarning-test.js | 2 + .../__tests__/ReactSuspenseCallback-test.js | 2 + .../ReactSuspenseEffectsSemantics-test.js | 2 + .../ReactSuspenseEffectsSemanticsDOM-test.js | 2 + .../__tests__/ReactSuspenseFallback-test.js | 2 + .../src/__tests__/ReactSuspenseList-test.js | 2 + .../ReactSuspenseWithNoopRenderer-test.js | 2 + .../ReactSuspenseyCommitPhase-test.js | 2 + .../__tests__/ReactTopLevelFragment-test.js | 1 + .../src/__tests__/ReactTopLevelText-test.js | 1 + .../src/__tests__/ReactTransition-test.js | 1 + .../__tests__/ReactTransitionTracing-test.js | 2 + .../src/__tests__/ReactUpdatePriority-test.js | 2 + .../src/__tests__/ReactUse-test.js | 2 + .../src/__tests__/StrictEffectsMode-test.js | 1 + .../src/__tests__/useEffectEvent-test.js | 4 +- .../src/__tests__/useMemoCache-test.js | 2 + .../__tests__/useSyncExternalStore-test.js | 2 + .../src/__tests__/ReactFresh-test.js | 1 + .../__tests__/ReactFreshIntegration-test.js | 1 + .../ReactFlightTurbopackDOMBrowser-test.js | 2 + .../ReactFlightTurbopackDOMEdge-test.js | 2 + .../ReactFlightTurbopackDOMForm-test.js | 1 + .../ReactFlightTurbopackDOMNode-test.js | 2 + .../ReactFlightTurbopackDOMReply-test.js | 1 + .../ReactFlightTurbopackDOMReplyEdge-test.js | 1 + .../src/__tests__/ReactFlightDOM-test.js | 2 + .../__tests__/ReactFlightDOMBrowser-test.js | 2 + .../src/__tests__/ReactFlightDOMEdge-test.js | 2 + .../src/__tests__/ReactFlightDOMForm-test.js | 1 + .../src/__tests__/ReactFlightDOMNode-test.js | 2 + .../src/__tests__/ReactFlightDOMReply-test.js | 1 + .../__tests__/ReactFlightDOMReplyEdge-test.js | 1 + .../src/__tests__/ReactServer-test.js | 2 + .../src/__tests__/ReactTestRenderer-test.js | 1 + .../__tests__/ReactTestRendererAct-test.js | 1 + .../__tests__/ReactTestRendererAsync-test.js | 2 + .../ReactTestRendererTraversal-test.js | 1 + .../react/src/__tests__/ReactChildren-test.js | 1 + .../__tests__/ReactContextValidator-test.js | 2 + .../src/__tests__/ReactCreateElement-test.js | 2 + .../src/__tests__/ReactCreateRef-test.js | 2 + .../react/src/__tests__/ReactFetch-test.js | 1 + .../src/__tests__/ReactFetchEdge-test.js | 1 + .../ReactJSXElementValidator-test.js | 2 + .../src/__tests__/ReactJSXRuntime-test.js | 2 + .../ReactJSXTransformIntegration-test.js | 2 + .../__tests__/ReactStartTransition-test.js | 1 + .../src/__tests__/ReactStrictMode-test.js | 7 + .../createReactClassIntegration-test.js | 1 + .../react/src/__tests__/forwardRef-test.js | 1 + .../scheduler/src/__tests__/Scheduler-test.js | 1 + .../src/__tests__/SchedulerMock-test.js | 1 + .../src/__tests__/SchedulerPostTask-test.js | 1 + .../src/__tests__/SchedulerProfiling-test.js | 1 + .../__tests__/SchedulerSetImmediate-test.js | 1 + .../src/__tests__/SchedulerSetTimeout-test.js | 3 + .../__tests__/ReactDOMFrameScheduling-test.js | 2 + .../src/__tests__/useSubscription-test.js | 1 + .../useSyncExternalStoreNative-test.js | 2 + .../useSyncExternalStoreShared-test.js | 2 + .../useSyncExternalStoreShimServer-test.js | 2 + scripts/jest/config.base.js | 1 - 198 files changed, 391 insertions(+), 98 deletions(-) diff --git a/packages/react-art/src/__tests__/ReactART-test.js b/packages/react-art/src/__tests__/ReactART-test.js index 063c8df8244c5..b59af8ee02b9d 100644 --- a/packages/react-art/src/__tests__/ReactART-test.js +++ b/packages/react-art/src/__tests__/ReactART-test.js @@ -22,11 +22,21 @@ import Circle from 'react-art/Circle'; import Rectangle from 'react-art/Rectangle'; import Wedge from 'react-art/Wedge'; -let ReactDOMClient; -let act; -let ReactTestRenderer; -let ReactNoop; -let Scheduler; +// Isolate DOM renderer. +jest.resetModules(); + +const ReactDOMClient = require('react-dom/client'); +const act = require('internal-test-utils').act; + +// Isolate test renderer. +jest.resetModules(); +const ReactTestRenderer = require('react-test-renderer'); + +// Isolate the noop renderer +jest.resetModules(); +const ReactNoop = require('react-noop-renderer'); +const Scheduler = require('scheduler'); + let Group; let Shape; let Surface; @@ -63,21 +73,6 @@ describe('ReactART', () => { let container; beforeEach(() => { - // Isolate DOM renderer. - jest.resetModules(); - - ReactDOMClient = require('react-dom/client'); - act = require('internal-test-utils').act; - - // Isolate test renderer. - jest.resetModules(); - ReactTestRenderer = require('react-test-renderer'); - - // Isolate the noop renderer - jest.resetModules(); - ReactNoop = require('react-noop-renderer'); - Scheduler = require('scheduler'); - container = document.createElement('div'); document.body.appendChild(container); diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js index 52c127397e6d8..13027da0234af 100644 --- a/packages/react-client/src/__tests__/ReactFlight-test.js +++ b/packages/react-client/src/__tests__/ReactFlight-test.js @@ -42,6 +42,7 @@ let assertLog; describe('ReactFlight', () => { beforeEach(() => { + jest.resetModules(); jest.mock('react', () => require('react/react.react-server')); ReactServer = require('react'); ReactNoopFlightServer = require('react-noop-renderer/flight-server'); diff --git a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js index 695efc7418ad3..eabcbd215bfb2 100644 --- a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js @@ -34,6 +34,8 @@ describe('React hooks DevTools integration', () => { onCommitFiberUnmount: () => {}, }; + jest.resetModules(); + React = require('react'); ReactDebugTools = require('react-debug-tools'); ReactTestRenderer = require('react-test-renderer'); diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js index 4846a1fb20750..e02debaba101f 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js @@ -15,6 +15,7 @@ let ReactDebugTools; describe('ReactHooksInspection', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDebugTools = require('react-debug-tools'); }); diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index b6224f2dfa76e..076602fed456a 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -19,6 +19,7 @@ let useMemoCache; describe('ReactHooksInspectionIntegration', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactTestRenderer = require('react-test-renderer'); ReactDOM = require('react-dom'); diff --git a/packages/react-devtools-shared/src/__tests__/console-test.js b/packages/react-devtools-shared/src/__tests__/console-test.js index 384b28c976858..e8f5376c7bf2e 100644 --- a/packages/react-devtools-shared/src/__tests__/console-test.js +++ b/packages/react-devtools-shared/src/__tests__/console-test.js @@ -924,6 +924,8 @@ describe('console', () => { describe('console error', () => { beforeEach(() => { + jest.resetModules(); + const Console = require('react-devtools-shared/src/backend/console'); patchConsole = Console.patch; unpatchConsole = Console.unpatch; diff --git a/packages/react-devtools-shared/src/hooks/__tests__/parseHookNames-test.js b/packages/react-devtools-shared/src/hooks/__tests__/parseHookNames-test.js index 254a17717fbc4..01135909b5692 100644 --- a/packages/react-devtools-shared/src/hooks/__tests__/parseHookNames-test.js +++ b/packages/react-devtools-shared/src/hooks/__tests__/parseHookNames-test.js @@ -48,6 +48,8 @@ describe('parseHookNames', () => { let parseHookNames; beforeEach(() => { + jest.resetModules(); + jest.mock('source-map-support', () => { console.trace('source-map-support'); }); diff --git a/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js b/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js index 05e1d1234e991..87885ca07b4a5 100644 --- a/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js +++ b/packages/react-dom/src/__tests__/DOMPropertyOperations-test.js @@ -21,6 +21,7 @@ describe('DOMPropertyOperations', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ({act} = require('internal-test-utils')); diff --git a/packages/react-dom/src/__tests__/InvalidEventListeners-test.js b/packages/react-dom/src/__tests__/InvalidEventListeners-test.js index de35dae0f967d..e7c9b5f9610ca 100644 --- a/packages/react-dom/src/__tests__/InvalidEventListeners-test.js +++ b/packages/react-dom/src/__tests__/InvalidEventListeners-test.js @@ -18,6 +18,7 @@ describe('InvalidEventListeners', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.js b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.js index cf8e5203a5d49..1dd665ce01145 100644 --- a/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.js +++ b/packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.js @@ -45,6 +45,7 @@ let container; // It should probably be rewritten but we're keeping it for some extra coverage. describe('ReactBrowserEventEmitter', () => { beforeEach(() => { + jest.resetModules(); LISTENER.mockClear(); React = require('react'); diff --git a/packages/react-dom/src/__tests__/ReactChildReconciler-test.js b/packages/react-dom/src/__tests__/ReactChildReconciler-test.js index 2e1d9418c8cf8..ef584a7856921 100644 --- a/packages/react-dom/src/__tests__/ReactChildReconciler-test.js +++ b/packages/react-dom/src/__tests__/ReactChildReconciler-test.js @@ -18,6 +18,8 @@ let act; describe('ReactChildReconciler', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactComponent-test.js b/packages/react-dom/src/__tests__/ReactComponent-test.js index 7be43e9cef806..5fa2a4f9f2e6e 100644 --- a/packages/react-dom/src/__tests__/ReactComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactComponent-test.js @@ -17,6 +17,8 @@ let act; describe('ReactComponent', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js index a05e7bd16fc28..4567ee62a0a3e 100644 --- a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js +++ b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js @@ -90,6 +90,8 @@ function getLifeCycleState(instance): ComponentLifeCycle { */ describe('ReactComponentLifeCycle', () => { beforeEach(() => { + jest.resetModules(); + act = require('internal-test-utils').act; React = require('react'); diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index b478f4fe37e8b..c58e825203f8e 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -63,6 +63,7 @@ describe('ReactCompositeComponent', () => { } beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js index 299efe1672cd5..a2894b2ca7b27 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js @@ -520,82 +520,78 @@ describe('ReactCompositeComponent-state', () => { assertLog([ 'render -- step: 3, extra: false', 'callback -- step: 3, extra: false', + + // A second time for the retry. + 'render -- step: 3, extra: false', + 'callback -- step: 3, extra: false', ]); }); - // @gate !disableModulePatternComponents - it('should support stateful module pattern components', async () => { - function Child() { - return { - state: { - count: 123, - }, - render() { - return
{`count:${this.state.count}`}
; - }, - }; - } - - const el = document.createElement('div'); - const root = ReactDOMClient.createRoot(el); - expect(() => { - ReactDOM.flushSync(() => { - root.render(); - }); - }).toErrorDev( - 'Warning: The component appears to be a function component that returns a class instance. ' + - 'Change Child to a class that extends React.Component instead. ' + - "If you can't use a class try assigning the prototype on the function as a workaround. " + - '`Child.prototype = React.Component.prototype`. ' + - "Don't use an arrow function since it cannot be called with `new` by React.", - ); + if (!require('shared/ReactFeatureFlags').disableModulePatternComponents) { + it('should support stateful module pattern components', async () => { + function Child() { + return { + state: { + count: 123, + }, + render() { + return
{`count:${this.state.count}`}
; + }, + }; + } + + const el = document.createElement('div'); + const root = ReactDOMClient.createRoot(el); + expect(() => { + ReactDOM.flushSync(() => { + root.render(); + }); + }).toErrorDev( + 'Warning: The component appears to be a function component that returns a class instance. ' + + 'Change Child to a class that extends React.Component instead. ' + + "If you can't use a class try assigning the prototype on the function as a workaround. " + + '`Child.prototype = React.Component.prototype`. ' + + "Don't use an arrow function since it cannot be called with `new` by React.", + ); - expect(el.textContent).toBe('count:123'); - }); + expect(el.textContent).toBe('count:123'); + }); - // @gate !disableModulePatternComponents - it('should support getDerivedStateFromProps for module pattern components', async () => { - function Child() { - return { - state: { - count: 1, - }, - render() { - return
{`count:${this.state.count}`}
; - }, - }; - } - Child.getDerivedStateFromProps = (props, prevState) => { - return { - count: prevState.count + props.incrementBy, + it('should support getDerivedStateFromProps for module pattern components', async () => { + function Child() { + return { + state: { + count: 1, + }, + render() { + return
{`count:${this.state.count}`}
; + }, + }; + } + Child.getDerivedStateFromProps = (props, prevState) => { + return { + count: prevState.count + props.incrementBy, + }; }; - }; - const el = document.createElement('div'); - const root = ReactDOMClient.createRoot(el); - expect(() => { - ReactDOM.flushSync(() => { + const el = document.createElement('div'); + const root = ReactDOMClient.createRoot(el); + await act(() => { root.render(); }); - }).toErrorDev( - 'Warning: The component appears to be a function component that returns a class instance. ' + - 'Change Child to a class that extends React.Component instead. ' + - "If you can't use a class try assigning the prototype on the function as a workaround. " + - '`Child.prototype = React.Component.prototype`. ' + - "Don't use an arrow function since it cannot be called with `new` by React.", - ); - expect(el.textContent).toBe('count:1'); - await act(() => { - root.render(); - }); - expect(el.textContent).toBe('count:3'); + expect(el.textContent).toBe('count:1'); + await act(() => { + root.render(); + }); + expect(el.textContent).toBe('count:3'); - await act(() => { - root.render(); + await act(() => { + root.render(); + }); + expect(el.textContent).toBe('count:4'); }); - expect(el.textContent).toBe('count:4'); - }); + } it('should not support setState in componentWillUnmount', async () => { let subscription; diff --git a/packages/react-dom/src/__tests__/ReactDOM-test.js b/packages/react-dom/src/__tests__/ReactDOM-test.js index b12226d201d51..00356cc725392 100644 --- a/packages/react-dom/src/__tests__/ReactDOM-test.js +++ b/packages/react-dom/src/__tests__/ReactDOM-test.js @@ -19,6 +19,7 @@ let act; describe('ReactDOM', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js b/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js index 0d0dcfa32c7fa..e88bde84826b9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js @@ -15,6 +15,7 @@ describe('ReactDOM unknown attribute', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js index 3126ef8119bd1..006b29fd97ab3 100644 --- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js @@ -20,6 +20,7 @@ describe('ReactDOMComponent', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js b/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js index 7072a58acac11..ad5826fe393ea 100644 --- a/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js @@ -19,6 +19,7 @@ describe('ReactDOMConsoleErrorReporting', () => { let waitForThrow; beforeEach(() => { + jest.resetModules(); act = require('internal-test-utils').act; React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReportingLegacy-test.js b/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReportingLegacy-test.js index 11ad2c99bcb75..bb1e9c83ecf65 100644 --- a/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReportingLegacy-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMConsoleErrorReportingLegacy-test.js @@ -19,6 +19,7 @@ describe('ReactDOMConsoleErrorReporting', () => { let waitForThrow; beforeEach(() => { + jest.resetModules(); act = require('internal-test-utils').act; React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js b/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js index 8a05453848d24..f059d7bd2f560 100644 --- a/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMEventListener-test.js @@ -18,6 +18,7 @@ describe('ReactDOMEventListener', () => { let simulateEventDispatch; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js b/packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js index dbb9409cea268..b90ca9efdb32e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js @@ -18,6 +18,7 @@ describe('ReactDOMEventListener', () => { beforeEach(() => { window.TextEvent = function () {}; + jest.resetModules(); jest.isolateModules(() => { React = require('react'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js index 6b9eb722282ce..94172ab77b237 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js @@ -22,6 +22,7 @@ describe('ReactDOMFiber', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); PropTypes = require('prop-types'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzDeferredValue-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzDeferredValue-test.js index 6120a0ef0e2e7..0b3335dfbacb8 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzDeferredValue-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzDeferredValue-test.js @@ -32,6 +32,7 @@ let Suspense; describe('ReactDOMFizzForm', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); Scheduler = require('scheduler'); ReactDOMServer = require('react-dom/server.browser'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js index 9385e53b92f6b..ae56c5eae4dd2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js @@ -27,6 +27,7 @@ let useFormState; describe('ReactDOMFizzForm', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server.browser'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js index 0e16d217ea150..5a796c5446f06 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js @@ -49,6 +49,7 @@ let streamingContainer; describe('ReactDOMFizzServer', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; const jsdom = new JSDOM( diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js index d3d44a24fe0e5..ab5f8509260df 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js @@ -20,6 +20,7 @@ let Suspense; describe('ReactDOMFizzServerBrowser', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMFizzServer = require('react-dom/server.browser'); Suspense = React.Suspense; diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerEdge-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerEdge-test.js index b75fc78716977..c442f1813836c 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerEdge-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerEdge-test.js @@ -21,6 +21,7 @@ let ReactDOMFizzServer; describe('ReactDOMFizzServerEdge', () => { beforeEach(() => { + jest.resetModules(); jest.useRealTimers(); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js index 748d9ed7c58d0..f7bab722bb386 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js @@ -17,6 +17,7 @@ let Suspense; describe('ReactDOMFizzServerNode', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMFizzServer = require('react-dom/server'); Stream = require('stream'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js index 8838acfb1e37f..3c2260d83bd6f 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzShellHydration-test.js @@ -27,6 +27,7 @@ let assertLog; describe('ReactDOMFizzShellHydration', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js index 83fcf4a6d131b..49afa26f65e02 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js @@ -27,6 +27,7 @@ let fatalError = undefined; describe('ReactDOMFizzStatic', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js index d063ba798b8ab..7482c7adaac8c 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js @@ -29,6 +29,7 @@ let container; describe('ReactDOMFizzStaticBrowser', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMFizzServer = require('react-dom/server.browser'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzStaticFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzStaticFloat-test.js index eafe097f9b871..9a825bf1e3871 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzStaticFloat-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzStaticFloat-test.js @@ -28,6 +28,7 @@ let container; describe('ReactDOMFizzStaticFloat', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMFizzServer = require('react-dom/server.browser'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js index c22c688432775..a049ec4c49222 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js @@ -16,6 +16,7 @@ let Suspense; describe('ReactDOMFizzStaticNode', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); if (__EXPERIMENTAL__) { ReactDOMFizzStatic = require('react-dom/static'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzSuppressHydrationWarning-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzSuppressHydrationWarning-test.js index 7c145dc145d7e..3300297b77ee0 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzSuppressHydrationWarning-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzSuppressHydrationWarning-test.js @@ -26,6 +26,7 @@ let waitForAll; describe('ReactDOMFizzServerHydrationWarning', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; Scheduler = require('scheduler'); React = require('react'); diff --git a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js index 8ab5e1db04680..eaad571ad9759 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js @@ -40,6 +40,7 @@ let streamingContainer; describe('ReactDOMFloat', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; const jsdom = new JSDOM( diff --git a/packages/react-dom/src/__tests__/ReactDOMForm-test.js b/packages/react-dom/src/__tests__/ReactDOMForm-test.js index 9d2e37f49db5e..795909b6eaf46 100644 --- a/packages/react-dom/src/__tests__/ReactDOMForm-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMForm-test.js @@ -44,6 +44,7 @@ describe('ReactDOMForm', () => { let useFormState; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMHooks-test.js b/packages/react-dom/src/__tests__/ReactDOMHooks-test.js index ccf555a4f9b14..ad8fadad1ff97 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHooks-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHooks-test.js @@ -19,6 +19,8 @@ describe('ReactDOMHooks', () => { let container; beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js index ff150066f9a1b..76a8229e5a89f 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js @@ -21,6 +21,7 @@ describe('ReactDOMServerHydration', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMInReactServer-test.js b/packages/react-dom/src/__tests__/ReactDOMInReactServer-test.js index f1067ef3d4922..f3bc6ea8aded2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInReactServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInReactServer-test.js @@ -11,6 +11,7 @@ describe('ReactDOMInReactServer', () => { beforeEach(() => { + jest.resetModules(); jest.mock('react', () => require('react/react.react-server')); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMInput-test.js b/packages/react-dom/src/__tests__/ReactDOMInput-test.js index dc9456bc8bb72..2ccd1c043661a 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInput-test.js @@ -79,6 +79,8 @@ describe('ReactDOMInput', () => { } beforeEach(() => { + jest.resetModules(); + setUntrackedValue = Object.getOwnPropertyDescriptor( HTMLInputElement.prototype, 'value', diff --git a/packages/react-dom/src/__tests__/ReactDOMInvalidARIAHook-test.js b/packages/react-dom/src/__tests__/ReactDOMInvalidARIAHook-test.js index ca262e28b7e44..1768ec14ea9e0 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInvalidARIAHook-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInvalidARIAHook-test.js @@ -16,6 +16,7 @@ describe('ReactDOMInvalidARIAHook', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactDOMLegacyFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMLegacyFloat-test.js index f05dd4a444198..94876e41641f9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMLegacyFloat-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMLegacyFloat-test.js @@ -15,6 +15,8 @@ let ReactDOMFizzServer; describe('ReactDOMFloat', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMFizzServer = require('react-dom/server'); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js b/packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js index c549af0cee062..6b445f9cf8d61 100644 --- a/packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js @@ -22,6 +22,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => { let container; beforeEach(() => { + jest.resetModules(); container = document.createElement('div'); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMNestedEvents-test.js b/packages/react-dom/src/__tests__/ReactDOMNestedEvents-test.js index 89841f7ef955d..f7b0db175e5f6 100644 --- a/packages/react-dom/src/__tests__/ReactDOMNestedEvents-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMNestedEvents-test.js @@ -18,6 +18,7 @@ describe('ReactDOMNestedEvents', () => { let assertLog; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); diff --git a/packages/react-dom/src/__tests__/ReactDOMOption-test.js b/packages/react-dom/src/__tests__/ReactDOMOption-test.js index 8d6849e32ec7a..c0597c36b20d1 100644 --- a/packages/react-dom/src/__tests__/ReactDOMOption-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMOption-test.js @@ -17,6 +17,7 @@ describe('ReactDOMOption', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMRoot-test.js b/packages/react-dom/src/__tests__/ReactDOMRoot-test.js index 8453150a38a35..7967cf84a2672 100644 --- a/packages/react-dom/src/__tests__/ReactDOMRoot-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMRoot-test.js @@ -24,6 +24,7 @@ describe('ReactDOMRoot', () => { let container; beforeEach(() => { + jest.resetModules(); container = document.createElement('div'); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js b/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js index b137ead3c34a1..17b1aed89ce72 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js @@ -43,6 +43,7 @@ describe('ReactDOMSafariMicrotaskBug-test', () => { } }; + jest.resetModules(); container = document.createElement('div'); React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMSelect-test.js b/packages/react-dom/src/__tests__/ReactDOMSelect-test.js index c61289011d6ae..35aaba29a6a46 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSelect-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMSelect-test.js @@ -26,6 +26,7 @@ describe('ReactDOMSelect', () => { const noop = function () {}; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js index 1acbda0c29177..bda021b5e06a7 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js @@ -20,6 +20,8 @@ let ReactTestUtils; let ReactDOMServer; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js index 25a443da7d55e..2821dd088bb48 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationBasic-test.js @@ -20,6 +20,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js index bfc6d410bfaa0..178ed7982a44f 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationCheckbox-test.js @@ -20,6 +20,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js index 28db8815550f7..2df2d66b9b9fa 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationClassContextType-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js index 2e1f419ca945f..ea30b45e3d61c 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js @@ -22,6 +22,7 @@ let ReactFeatureFlags; let ReactTestUtils; function initModules() { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js index 586fe8b016e82..8e8fc2aa8fe27 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationFragment-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js index 6f42b23ca9fcc..7e46bea5f93d9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js @@ -35,6 +35,9 @@ let yieldValue; let clearLog; function initModules() { + // Reset warning cache. + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js index 4dfc3628f749d..54780dae52cdb 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationInput-test.js @@ -20,6 +20,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js index a9594872155e0..1481fcd326bb0 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js @@ -19,6 +19,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); PropTypes = require('prop-types'); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js index 2ea05bd56ed36..99cf33b821f17 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationModes-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js index a460e2104ce88..bd4797f9ef146 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationReconnecting-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationReconnecting-test.js index 5329a419d4283..76612f510d7d2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationReconnecting-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationReconnecting-test.js @@ -19,6 +19,9 @@ let ReactTestUtils; describe('ReactDOMServerIntegration', () => { function initModules() { + // Reset warning cache. + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); @@ -456,6 +459,9 @@ describe('ReactDOMServerIntegration', () => { describe('ReactDOMServerIntegration (legacy)', () => { function initModules() { + // Reset warning cache. + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationRefs-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationRefs-test.js index d14b38f3dcb8f..e5564d3d9348c 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationRefs-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationRefs-test.js @@ -17,6 +17,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js index bc55cf89232ee..9e503be7520b2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSelect-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js index 94336a7611c67..8ea1c9d53baee 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationSpecialTypes-test.js @@ -23,6 +23,8 @@ let log; let clearLog; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js index 07e65b7eabdb2..dd19385e62c56 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationTextarea-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js index f0780da48a628..55336a2cb5636 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUntrustedURL-test.js @@ -32,6 +32,7 @@ describe('ReactDOMServerIntegration - Untrusted URLs', () => { } function initModules() { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); @@ -196,6 +197,7 @@ describe('ReactDOMServerIntegration - Untrusted URLs - disableJavaScriptURLs', ( } function initModules() { + jest.resetModules(); const ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.disableJavaScriptURLs = true; diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUserInteraction-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUserInteraction-test.js index 5d6abf288d2ba..bc5980f23dda2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUserInteraction-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationUserInteraction-test.js @@ -17,6 +17,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js index 53999c560c25f..8b3ea97816427 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js @@ -15,6 +15,8 @@ let React; let ReactDOMServer; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMShorthandCSSPropertyCollision-test.js b/packages/react-dom/src/__tests__/ReactDOMShorthandCSSPropertyCollision-test.js index 7cd7c77b0fea7..b04bbb0ab4eb3 100644 --- a/packages/react-dom/src/__tests__/ReactDOMShorthandCSSPropertyCollision-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMShorthandCSSPropertyCollision-test.js @@ -16,6 +16,8 @@ describe('ReactDOMShorthandCSSPropertyCollision', () => { let ReactDOMClient; beforeEach(() => { + jest.resetModules(); + act = require('internal-test-utils').act; React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMSingletonComponents-test.js b/packages/react-dom/src/__tests__/ReactDOMSingletonComponents-test.js index 65bc8a830dd3e..9c4c3fc913be1 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSingletonComponents-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMSingletonComponents-test.js @@ -26,6 +26,7 @@ let waitForAll; describe('ReactDOM HostSingleton', () => { beforeEach(() => { + jest.resetModules(); JSDOM = require('jsdom').JSDOM; React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js b/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js index 1f655eee2ed4e..537e448f86dd8 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js @@ -21,6 +21,7 @@ describe('ReactDOMSuspensePlaceholder', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js b/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js index c194b8184b964..65bb49e06a1c8 100644 --- a/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMTestSelectors-test.js @@ -27,7 +27,10 @@ describe('ReactDOMTestSelectors', () => { let container; beforeEach(() => { + jest.resetModules(); + React = require('react'); + act = require('internal-test-utils').act; if (__EXPERIMENTAL__ || global.__WWW__) { diff --git a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js index 74b46850911aa..3d21ca64e399e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js @@ -22,6 +22,8 @@ describe('ReactDOMTextarea', () => { const ReactFeatureFlags = require('shared/ReactFeatureFlags'); beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js b/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js index 1a64e54d6f37e..cf51eff4aced3 100644 --- a/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMserverIntegrationProgress-test.js @@ -18,6 +18,8 @@ let ReactDOMServer; let ReactTestUtils; function initModules() { + // Reset warning cache. + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.js b/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.js index efb66e7a4fbfc..4c6a0bed84a6c 100644 --- a/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.js +++ b/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.js @@ -16,6 +16,7 @@ let waitForAll; describe('ReactDeprecationWarnings', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); const InternalTestUtils = require('internal-test-utils'); diff --git a/packages/react-dom/src/__tests__/ReactEmptyComponent-test.js b/packages/react-dom/src/__tests__/ReactEmptyComponent-test.js index c2586a4d2a237..9316ad4392f61 100644 --- a/packages/react-dom/src/__tests__/ReactEmptyComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactEmptyComponent-test.js @@ -21,6 +21,8 @@ let container; describe('ReactEmptyComponent', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactEventIndependence-test.js b/packages/react-dom/src/__tests__/ReactEventIndependence-test.js index 085f07bbed98c..05cbca61752f6 100644 --- a/packages/react-dom/src/__tests__/ReactEventIndependence-test.js +++ b/packages/react-dom/src/__tests__/ReactEventIndependence-test.js @@ -15,6 +15,8 @@ let act; describe('ReactEventIndependence', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js index fffca3675a711..2d04c4af90937 100644 --- a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js @@ -21,6 +21,7 @@ function FunctionComponent(props) { describe('ReactFunctionComponent', () => { beforeEach(() => { + jest.resetModules(); PropTypes = require('prop-types'); React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactIdentity-test.js b/packages/react-dom/src/__tests__/ReactIdentity-test.js index 98e8e0533cecb..5c25daf7d8f30 100644 --- a/packages/react-dom/src/__tests__/ReactIdentity-test.js +++ b/packages/react-dom/src/__tests__/ReactIdentity-test.js @@ -16,6 +16,7 @@ let act; describe('ReactIdentity', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactTestUtils = require('react-dom/test-utils'); diff --git a/packages/react-dom/src/__tests__/ReactLegacyCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactLegacyCompositeComponent-test.js index 96629906f7cf5..42908a693cce3 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactLegacyCompositeComponent-test.js @@ -17,6 +17,7 @@ let act; describe('ReactLegacyCompositeComponent', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactLegacyMount-test.js b/packages/react-dom/src/__tests__/ReactLegacyMount-test.js index d33325bd4dd98..78492811428c3 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyMount-test.js +++ b/packages/react-dom/src/__tests__/ReactLegacyMount-test.js @@ -22,6 +22,8 @@ let waitForAll; describe('ReactMount', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactLegacyRootWarnings-test.js b/packages/react-dom/src/__tests__/ReactLegacyRootWarnings-test.js index 23da335dce0e0..9504de2c0a97e 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyRootWarnings-test.js +++ b/packages/react-dom/src/__tests__/ReactLegacyRootWarnings-test.js @@ -4,6 +4,7 @@ describe('ReactDOMRoot', () => { let container; beforeEach(() => { + jest.resetModules(); container = document.createElement('div'); ReactDOM = require('react-dom'); }); diff --git a/packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js b/packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js index 462e90f2c04ca..d1e54dbb055ca 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js +++ b/packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js @@ -20,6 +20,7 @@ let assertLog; // Can be deleted when we remove both. describe('ReactLegacyUpdates', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactTestUtils = require('react-dom/test-utils'); diff --git a/packages/react-dom/src/__tests__/ReactMultiChild-test.js b/packages/react-dom/src/__tests__/ReactMultiChild-test.js index cf31e0914547f..96413378f6aef 100644 --- a/packages/react-dom/src/__tests__/ReactMultiChild-test.js +++ b/packages/react-dom/src/__tests__/ReactMultiChild-test.js @@ -15,6 +15,7 @@ describe('ReactMultiChild', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/__tests__/ReactMultiChildReconcile-test.js b/packages/react-dom/src/__tests__/ReactMultiChildReconcile-test.js index 1c10335e9b524..3a2a5126882ce 100644 --- a/packages/react-dom/src/__tests__/ReactMultiChildReconcile-test.js +++ b/packages/react-dom/src/__tests__/ReactMultiChildReconcile-test.js @@ -304,6 +304,10 @@ async function testPropsSequence(sequence) { } describe('ReactMultiChildReconcile', () => { + beforeEach(() => { + jest.resetModules(); + }); + it('should reset internal state if removed then readded in an array', async () => { // Test basics. const props = { diff --git a/packages/react-dom/src/__tests__/ReactRenderDocument-test.js b/packages/react-dom/src/__tests__/ReactRenderDocument-test.js index e828889995ed4..3eab0e6c3661b 100644 --- a/packages/react-dom/src/__tests__/ReactRenderDocument-test.js +++ b/packages/react-dom/src/__tests__/ReactRenderDocument-test.js @@ -30,6 +30,8 @@ function getTestDocument(markup) { describe('rendering React components at document', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js index b95c20f9e3182..3b398a47feb28 100644 --- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js @@ -17,6 +17,7 @@ let ReactCurrentDispatcher; describe('ReactDOMServer', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); PropTypes = require('prop-types'); ReactDOMServer = require('react-dom/server'); diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingBrowser-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingBrowser-test.js index 375e12ec176b9..e99bc4904d1e4 100644 --- a/packages/react-dom/src/__tests__/ReactServerRenderingBrowser-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRenderingBrowser-test.js @@ -16,6 +16,7 @@ let ReactDOMServerBrowser; describe('ReactServerRenderingBrowser', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server'); // For extra isolation between what would be two bundles on npm diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js index 1b054e6530c89..c7416b255d471 100644 --- a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js @@ -22,6 +22,7 @@ let act; // If a test only needs ReactDOMServer, put it in ReactServerRendering-test instead. describe('ReactDOMServerHydration', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js b/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js index b7f4890fac9d1..9f24801907ba1 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js @@ -81,6 +81,7 @@ describe('ReactTestUtils.act()', () => { function runActTests(render, unmount, rerender) { describe('concurrent render', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactTestUtils = require('react-dom/test-utils'); diff --git a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js index 618317dab8e04..45babfd4032d3 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js @@ -27,6 +27,7 @@ function clearLog() { beforeEach(() => { prevActGlobal = global.IS_REACT_ACT_ENVIRONMENT; global.IS_REACT_ACT_ENVIRONMENT = true; + jest.resetModules(); jest.unmock('scheduler'); yields = []; React = require('react'); diff --git a/packages/react-dom/src/__tests__/ReactUpdates-test.js b/packages/react-dom/src/__tests__/ReactUpdates-test.js index cf6d0ccb9ecde..ea4d8480c7e61 100644 --- a/packages/react-dom/src/__tests__/ReactUpdates-test.js +++ b/packages/react-dom/src/__tests__/ReactUpdates-test.js @@ -21,6 +21,7 @@ let assertLog; describe('ReactUpdates', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/escapeTextForBrowser-test.js b/packages/react-dom/src/__tests__/escapeTextForBrowser-test.js index 22ae71222c370..be8dccf9f63ea 100644 --- a/packages/react-dom/src/__tests__/escapeTextForBrowser-test.js +++ b/packages/react-dom/src/__tests__/escapeTextForBrowser-test.js @@ -14,6 +14,7 @@ let ReactDOMServer; describe('escapeTextForBrowser', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server'); }); diff --git a/packages/react-dom/src/__tests__/quoteAttributeValueForBrowser-test.js b/packages/react-dom/src/__tests__/quoteAttributeValueForBrowser-test.js index b4274d04d0767..902e3c155c3ca 100644 --- a/packages/react-dom/src/__tests__/quoteAttributeValueForBrowser-test.js +++ b/packages/react-dom/src/__tests__/quoteAttributeValueForBrowser-test.js @@ -14,6 +14,7 @@ let ReactDOMServer; describe('quoteAttributeValueForBrowser', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server'); }); diff --git a/packages/react-dom/src/__tests__/refs-destruction-test.js b/packages/react-dom/src/__tests__/refs-destruction-test.js index bf391a18c3fbe..97009c9e77806 100644 --- a/packages/react-dom/src/__tests__/refs-destruction-test.js +++ b/packages/react-dom/src/__tests__/refs-destruction-test.js @@ -20,6 +20,8 @@ let theInnerClassComponentRef; describe('refs-destruction', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/__tests__/refs-test.js b/packages/react-dom/src/__tests__/refs-test.js index 916835fd03d7f..e42661abd5a1f 100644 --- a/packages/react-dom/src/__tests__/refs-test.js +++ b/packages/react-dom/src/__tests__/refs-test.js @@ -22,6 +22,7 @@ describe('reactiverefs', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactFeatureFlags = require('shared/ReactFeatureFlags'); @@ -232,6 +233,7 @@ if (!ReactFeatureFlags.disableModulePatternComponents) { describe('ref swapping', () => { let RefHopsAround; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactFeatureFlags = require('shared/ReactFeatureFlags'); @@ -567,14 +569,6 @@ describe('creating element with string ref in constructor', () => { }); describe('strings refs across renderers', () => { - beforeEach(() => { - React = require('react'); - ReactDOMClient = require('react-dom/client'); - ReactFeatureFlags = require('shared/ReactFeatureFlags'); - ReactTestUtils = require('react-dom/test-utils'); - act = require('internal-test-utils').act; - }); - it('does not break', async () => { class Parent extends React.Component { render() { @@ -590,13 +584,11 @@ describe('strings refs across renderers', () => { class Indirection extends React.Component { componentDidUpdate() { - jest.resetModules(); // One ref is being rendered later using another renderer copy. + jest.resetModules(); const AnotherCopyOfReactDOM = require('react-dom'); const AnotherCopyOfReactDOMClient = require('react-dom/client'); const root = AnotherCopyOfReactDOMClient.createRoot(div2); - - // TODO: this should error since flushSync is called in a lifecycle. AnotherCopyOfReactDOM.flushSync(() => { root.render(this.props.child2); }); diff --git a/packages/react-dom/src/__tests__/refsLegacy-test.js b/packages/react-dom/src/__tests__/refsLegacy-test.js index 5e19289d395c7..c3af817892ffa 100644 --- a/packages/react-dom/src/__tests__/refsLegacy-test.js +++ b/packages/react-dom/src/__tests__/refsLegacy-test.js @@ -14,6 +14,7 @@ let ReactDOM = require('react-dom'); describe('root level refs with legacy APIs', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); }); diff --git a/packages/react-dom/src/events/__tests__/SyntheticFocusEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticFocusEvent-test.js index bf4fab696741e..ef889c4b60d10 100644 --- a/packages/react-dom/src/events/__tests__/SyntheticFocusEvent-test.js +++ b/packages/react-dom/src/events/__tests__/SyntheticFocusEvent-test.js @@ -14,6 +14,7 @@ describe('SyntheticFocusEvent', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/events/__tests__/SyntheticMouseEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticMouseEvent-test.js index 5c252a74beb5c..a20886a3e2c04 100644 --- a/packages/react-dom/src/events/__tests__/SyntheticMouseEvent-test.js +++ b/packages/react-dom/src/events/__tests__/SyntheticMouseEvent-test.js @@ -17,6 +17,7 @@ describe('SyntheticMouseEvent', () => { let container; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js index dd5cc0130fb17..fab10a36e16d1 100644 --- a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js +++ b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js @@ -37,6 +37,7 @@ describe('ChangeEventPlugin', () => { let container; beforeEach(() => { + jest.resetModules(); // TODO pull this into helper method, reduce repetition. // mock the browser APIs which are used in schedule: // - calling 'window.postMessage' should actually fire postmessage handlers diff --git a/packages/react-dom/src/events/plugins/__tests__/EnterLeaveEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/EnterLeaveEventPlugin-test.js index ee4cb594f721f..569a29a22a5b8 100644 --- a/packages/react-dom/src/events/plugins/__tests__/EnterLeaveEventPlugin-test.js +++ b/packages/react-dom/src/events/plugins/__tests__/EnterLeaveEventPlugin-test.js @@ -18,6 +18,8 @@ describe('EnterLeaveEventPlugin', () => { let container; beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js index 1110c62e61977..4cd9c8f27e6f5 100644 --- a/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js +++ b/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js @@ -44,6 +44,7 @@ describe('SimpleEventPlugin', function () { } beforeEach(function () { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); @@ -256,6 +257,8 @@ describe('SimpleEventPlugin', function () { describe('interactive events, in concurrent mode', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index 07d90eae157d2..5b63eebd529fd 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -16,6 +16,8 @@ let SuspenseList; describe('ReactIs', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactIs = require('react-is'); diff --git a/packages/react-reconciler/src/__tests__/Activity-test.js b/packages/react-reconciler/src/__tests__/Activity-test.js index 780cb065c088c..fc6a8b563d197 100644 --- a/packages/react-reconciler/src/__tests__/Activity-test.js +++ b/packages/react-reconciler/src/__tests__/Activity-test.js @@ -16,6 +16,8 @@ let assertLog; describe('Activity', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ActivityStrictMode-test.js b/packages/react-reconciler/src/__tests__/ActivityStrictMode-test.js index b7a1306e28303..a8b8d286dc6aa 100644 --- a/packages/react-reconciler/src/__tests__/ActivityStrictMode-test.js +++ b/packages/react-reconciler/src/__tests__/ActivityStrictMode-test.js @@ -6,6 +6,7 @@ let log; describe('Activity StrictMode', () => { beforeEach(() => { + jest.resetModules(); log = []; React = require('react'); diff --git a/packages/react-reconciler/src/__tests__/ActivitySuspense-test.js b/packages/react-reconciler/src/__tests__/ActivitySuspense-test.js index c27b0de4cb507..a2b4de2e0ce51 100644 --- a/packages/react-reconciler/src/__tests__/ActivitySuspense-test.js +++ b/packages/react-reconciler/src/__tests__/ActivitySuspense-test.js @@ -15,6 +15,8 @@ let assertLog; describe('Activity Suspense', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactActWarnings-test.js b/packages/react-reconciler/src/__tests__/ReactActWarnings-test.js index 378e8b250caa2..61cde5648a9e6 100644 --- a/packages/react-reconciler/src/__tests__/ReactActWarnings-test.js +++ b/packages/react-reconciler/src/__tests__/ReactActWarnings-test.js @@ -24,6 +24,7 @@ let caches; // React 17. describe('act warnings', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); Scheduler = require('scheduler'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactAsyncActions-test.js b/packages/react-reconciler/src/__tests__/ReactAsyncActions-test.js index b8c5a9005d06f..0a29be2b6fec9 100644 --- a/packages/react-reconciler/src/__tests__/ReactAsyncActions-test.js +++ b/packages/react-reconciler/src/__tests__/ReactAsyncActions-test.js @@ -10,6 +10,8 @@ let textCache; describe('ReactAsyncActions', () => { beforeEach(() => { + jest.resetModules(); + global.reportError = error => { Scheduler.log('reportError: ' + error.message); }; diff --git a/packages/react-reconciler/src/__tests__/ReactCPUSuspense-test.js b/packages/react-reconciler/src/__tests__/ReactCPUSuspense-test.js index a504ed874d30f..d640f87205e45 100644 --- a/packages/react-reconciler/src/__tests__/ReactCPUSuspense-test.js +++ b/packages/react-reconciler/src/__tests__/ReactCPUSuspense-test.js @@ -15,6 +15,8 @@ let waitForPaint; describe('ReactSuspenseWithNoopRenderer', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactCache-test.js b/packages/react-reconciler/src/__tests__/ReactCache-test.js index 7caf1e7e9678f..b32479b70bbf5 100644 --- a/packages/react-reconciler/src/__tests__/ReactCache-test.js +++ b/packages/react-reconciler/src/__tests__/ReactCache-test.js @@ -17,6 +17,7 @@ let cache; describe('ReactCache', () => { beforeEach(() => { + jest.resetModules(); jest.mock('react', () => require('react/react.react-server')); React = require('react'); @@ -203,6 +204,7 @@ describe('ReactCache', () => { it('introspection of returned wrapper function is same on client and server', async () => { // When the variant flag is true, test the client version of `cache`. if (gate(flags => flags.variant)) { + jest.resetModules(); jest.mock('react', () => jest.requireActual('react')); const ClientReact = require('react'); cache = ClientReact.cache; diff --git a/packages/react-reconciler/src/__tests__/ReactCacheElement-test.js b/packages/react-reconciler/src/__tests__/ReactCacheElement-test.js index 4baae39b440eb..19d3180af650c 100644 --- a/packages/react-reconciler/src/__tests__/ReactCacheElement-test.js +++ b/packages/react-reconciler/src/__tests__/ReactCacheElement-test.js @@ -17,6 +17,8 @@ let seededCache; describe('ReactCacheElement', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Cache = React.unstable_Cache; diff --git a/packages/react-reconciler/src/__tests__/ReactClassSetStateCallback-test.js b/packages/react-reconciler/src/__tests__/ReactClassSetStateCallback-test.js index f4fa62a524ae3..e9b25f2ca74dc 100644 --- a/packages/react-reconciler/src/__tests__/ReactClassSetStateCallback-test.js +++ b/packages/react-reconciler/src/__tests__/ReactClassSetStateCallback-test.js @@ -6,6 +6,8 @@ let assertLog; describe('ReactClassSetStateCallback', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactConcurrentErrorRecovery-test.js b/packages/react-reconciler/src/__tests__/ReactConcurrentErrorRecovery-test.js index ffbf330a876c4..8c4f0d3415cec 100644 --- a/packages/react-reconciler/src/__tests__/ReactConcurrentErrorRecovery-test.js +++ b/packages/react-reconciler/src/__tests__/ReactConcurrentErrorRecovery-test.js @@ -12,6 +12,8 @@ let seededCache; describe('ReactConcurrentErrorRecovery', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactContextPropagation-test.js b/packages/react-reconciler/src/__tests__/ReactContextPropagation-test.js index 37c4771778554..3247e8758e079 100644 --- a/packages/react-reconciler/src/__tests__/ReactContextPropagation-test.js +++ b/packages/react-reconciler/src/__tests__/ReactContextPropagation-test.js @@ -13,6 +13,8 @@ let assertLog; describe('ReactLazyContextPropagation', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactDeferredValue-test.js b/packages/react-reconciler/src/__tests__/ReactDeferredValue-test.js index fb0de990d7d97..b321f4bba0de4 100644 --- a/packages/react-reconciler/src/__tests__/ReactDeferredValue-test.js +++ b/packages/react-reconciler/src/__tests__/ReactDeferredValue-test.js @@ -23,6 +23,8 @@ let textCache; describe('ReactDeferredValue', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactEffectOrdering-test.js b/packages/react-reconciler/src/__tests__/ReactEffectOrdering-test.js index 29ef30d639257..259492f294cfc 100644 --- a/packages/react-reconciler/src/__tests__/ReactEffectOrdering-test.js +++ b/packages/react-reconciler/src/__tests__/ReactEffectOrdering-test.js @@ -22,6 +22,7 @@ let assertLog; describe('ReactEffectOrdering', () => { beforeEach(() => { + jest.resetModules(); jest.useFakeTimers(); React = require('react'); diff --git a/packages/react-reconciler/src/__tests__/ReactExpiration-test.js b/packages/react-reconciler/src/__tests__/ReactExpiration-test.js index ef560f4ffe4c2..cd09ca347885b 100644 --- a/packages/react-reconciler/src/__tests__/ReactExpiration-test.js +++ b/packages/react-reconciler/src/__tests__/ReactExpiration-test.js @@ -25,6 +25,8 @@ let unstable_waitForExpired; describe('ReactExpiration', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); @@ -403,6 +405,7 @@ describe('ReactExpiration', () => { // Tests an implementation detail where expiration times are computed using // bitwise operations. + jest.resetModules(); Scheduler = require('scheduler'); if (gate(flags => flags.forceConcurrentByDefaultForTesting)) { diff --git a/packages/react-reconciler/src/__tests__/ReactFlushSync-test.js b/packages/react-reconciler/src/__tests__/ReactFlushSync-test.js index 8e965cc12bdbd..e2d9ba76660f9 100644 --- a/packages/react-reconciler/src/__tests__/ReactFlushSync-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFlushSync-test.js @@ -12,6 +12,8 @@ let waitForPaint; describe('ReactFlushSync', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactFlushSyncNoAggregateError-test.js b/packages/react-reconciler/src/__tests__/ReactFlushSyncNoAggregateError-test.js index 9f87497b3fd67..8c1bc7475be36 100644 --- a/packages/react-reconciler/src/__tests__/ReactFlushSyncNoAggregateError-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFlushSyncNoAggregateError-test.js @@ -11,6 +11,8 @@ let flushFakeMicrotasks; describe('ReactFlushSync (AggregateError not available)', () => { beforeEach(() => { + jest.resetModules(); + global.AggregateError = undefined; // When AggregateError is not available, the errors are rethrown in a diff --git a/packages/react-reconciler/src/__tests__/ReactFragment-test.js b/packages/react-reconciler/src/__tests__/ReactFragment-test.js index 29ad974f4ad99..3db7702f4cfef 100644 --- a/packages/react-reconciler/src/__tests__/ReactFragment-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFragment-test.js @@ -15,6 +15,8 @@ let waitForAll; describe('ReactFragment', () => { beforeEach(function () { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js index 204c1a2089e40..89d150ed09888 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js +++ b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js @@ -43,6 +43,7 @@ let assertLog; describe('ReactHooksWithNoopRenderer', () => { beforeEach(() => { + jest.resetModules(); jest.useFakeTimers(); React = require('react'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncremental-test.js b/packages/react-reconciler/src/__tests__/ReactIncremental-test.js index d3ddfa900524c..13f904bf9d014 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncremental-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncremental-test.js @@ -21,6 +21,7 @@ let assertLog; describe('ReactIncremental', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); @@ -2718,6 +2719,7 @@ describe('ReactIncremental', () => { // First, verify that this code path normally receives Fibers as keys, // and that they're not extensible. + jest.resetModules(); let receivedNonExtensibleObjects; // eslint-disable-next-line no-extend-native Map.prototype.set = function (key) { diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js index d366ccc0970fa..e56d0f30d7bce 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js @@ -18,6 +18,7 @@ let waitForThrow; describe('ReactIncrementalErrorLogging', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js index eb8ef9095a190..ed4317d95706e 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js @@ -17,6 +17,7 @@ let waitForThrow; describe('ReactIncrementalErrorReplay', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js index 65dba58d4fe7e..cffd690e64715 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js @@ -18,6 +18,8 @@ let waitForAll; describe('ReactIncrementalReflection', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js index 445ff979839e3..8c00ec741206e 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js @@ -21,6 +21,8 @@ let waitForPaint; describe('ReactIncrementalScheduling', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js index 9dac866df1ad7..b47897e54d92e 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js @@ -19,6 +19,8 @@ let waitForPaint; describe('ReactIncrementalSideEffects', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js index d75193883e3db..f3d5cbc675c52 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js @@ -21,6 +21,8 @@ let assertLog; describe('ReactIncrementalUpdates', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdatesMinimalism-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdatesMinimalism-test.js index 79110760d315e..5f1959de160af 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdatesMinimalism-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdatesMinimalism-test.js @@ -16,6 +16,7 @@ let act; describe('ReactIncrementalUpdatesMinimalism', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactInterleavedUpdates-test.js b/packages/react-reconciler/src/__tests__/ReactInterleavedUpdates-test.js index 47ea906808323..7e676861b5d31 100644 --- a/packages/react-reconciler/src/__tests__/ReactInterleavedUpdates-test.js +++ b/packages/react-reconciler/src/__tests__/ReactInterleavedUpdates-test.js @@ -11,6 +11,8 @@ let waitForPaint; describe('ReactInterleavedUpdates', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactMemo-test.js b/packages/react-reconciler/src/__tests__/ReactMemo-test.js index 2f51e8fc81b89..a7b47621d53e2 100644 --- a/packages/react-reconciler/src/__tests__/ReactMemo-test.js +++ b/packages/react-reconciler/src/__tests__/ReactMemo-test.js @@ -23,6 +23,8 @@ let assertLog; describe('memo', () => { beforeEach(() => { + jest.resetModules(); + PropTypes = require('prop-types'); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactNewContext-test.js b/packages/react-reconciler/src/__tests__/ReactNewContext-test.js index a6cabd6c641f7..e51ca08f2b8e8 100644 --- a/packages/react-reconciler/src/__tests__/ReactNewContext-test.js +++ b/packages/react-reconciler/src/__tests__/ReactNewContext-test.js @@ -20,6 +20,8 @@ let waitForThrow; describe('ReactNewContext', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); useContext = React.useContext; ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactPersistent-test.js b/packages/react-reconciler/src/__tests__/ReactPersistent-test.js index 06560430c7792..7900ccdadd451 100644 --- a/packages/react-reconciler/src/__tests__/ReactPersistent-test.js +++ b/packages/react-reconciler/src/__tests__/ReactPersistent-test.js @@ -16,6 +16,8 @@ let waitForAll; describe('ReactPersistent', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoopPersistent = require('react-noop-renderer/persistent'); const InternalTestUtils = require('internal-test-utils'); diff --git a/packages/react-reconciler/src/__tests__/ReactPersistentUpdatesMinimalism-test.js b/packages/react-reconciler/src/__tests__/ReactPersistentUpdatesMinimalism-test.js index 173b3064a5cba..359c80c247f02 100644 --- a/packages/react-reconciler/src/__tests__/ReactPersistentUpdatesMinimalism-test.js +++ b/packages/react-reconciler/src/__tests__/ReactPersistentUpdatesMinimalism-test.js @@ -16,6 +16,7 @@ let act; describe('ReactPersistentUpdatesMinimalism', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoopPersistent = require('react-noop-renderer/persistent'); act = require('internal-test-utils').act; diff --git a/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js b/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js index 7658fbadbae30..a29280b36c569 100644 --- a/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js @@ -25,6 +25,8 @@ let waitFor; describe('ReactSchedulerIntegration', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); @@ -193,6 +195,8 @@ describe( let logDuringShouldYield = false; beforeEach(() => { + jest.resetModules(); + jest.mock('scheduler', () => { const actual = jest.requireActual('scheduler/unstable_mock'); return { @@ -322,6 +326,8 @@ describe('`act` bypasses Scheduler methods completely,', () => { let infiniteLoopGuard; beforeEach(() => { + jest.resetModules(); + infiniteLoopGuard = 0; jest.mock('scheduler', () => { diff --git a/packages/react-reconciler/src/__tests__/ReactSubtreeFlagsWarning-test.js b/packages/react-reconciler/src/__tests__/ReactSubtreeFlagsWarning-test.js index 4ae9f7f61ca1c..49bde67837cdf 100644 --- a/packages/react-reconciler/src/__tests__/ReactSubtreeFlagsWarning-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSubtreeFlagsWarning-test.js @@ -12,6 +12,8 @@ let assertLog; describe('ReactSuspenseWithNoopRenderer', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js index 7e354f858a5ed..8706d9e248ce6 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js @@ -16,6 +16,8 @@ let act; describe('ReactSuspense', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemantics-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemantics-test.js index 8c8edb39c0f97..5200635b6fca4 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemantics-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemantics-test.js @@ -24,6 +24,8 @@ let assertLog; describe('ReactSuspenseEffectsSemantics', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js index 87eb80c3b2342..2a6b02acfe4f3 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js @@ -21,6 +21,8 @@ let fakeModuleCache; describe('ReactSuspenseEffectsSemanticsDOM', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseFallback-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseFallback-test.js index 07968fcae55c4..8dcf5fda13695 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseFallback-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseFallback-test.js @@ -17,6 +17,8 @@ let waitForAll; describe('ReactSuspenseFallback', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js index b5e753e4aca2a..432546c683f5b 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseList-test.js @@ -11,6 +11,8 @@ let waitFor; describe('ReactSuspenseList', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js index c1b8e34368378..77aae6ee53d9b 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js @@ -17,6 +17,8 @@ let seededCache; describe('ReactSuspenseWithNoopRenderer', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); Fragment = React.Fragment; ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseyCommitPhase-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseyCommitPhase-test.js index e64a2873b8541..52fd9ef3f27d8 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseyCommitPhase-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseyCommitPhase-test.js @@ -14,6 +14,8 @@ let waitForPaint; describe('ReactSuspenseyCommitPhase', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactTopLevelFragment-test.js b/packages/react-reconciler/src/__tests__/ReactTopLevelFragment-test.js index 20b307886fdd3..38b0d0a52633a 100644 --- a/packages/react-reconciler/src/__tests__/ReactTopLevelFragment-test.js +++ b/packages/react-reconciler/src/__tests__/ReactTopLevelFragment-test.js @@ -18,6 +18,7 @@ let waitForAll; // probably move to one of the other test files once it is official. describe('ReactTopLevelFragment', function () { beforeEach(function () { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactTopLevelText-test.js b/packages/react-reconciler/src/__tests__/ReactTopLevelText-test.js index 7fe6c4dfb84b2..30a3fa093b4ab 100644 --- a/packages/react-reconciler/src/__tests__/ReactTopLevelText-test.js +++ b/packages/react-reconciler/src/__tests__/ReactTopLevelText-test.js @@ -18,6 +18,7 @@ let waitForAll; // probably move to one of the other test files once it is official. describe('ReactTopLevelText', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/react-reconciler/src/__tests__/ReactTransition-test.js b/packages/react-reconciler/src/__tests__/ReactTransition-test.js index 67fc502d101ce..e5c69665f31c2 100644 --- a/packages/react-reconciler/src/__tests__/ReactTransition-test.js +++ b/packages/react-reconciler/src/__tests__/ReactTransition-test.js @@ -30,6 +30,7 @@ let seededCache; describe('ReactTransition', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactTransitionTracing-test.js b/packages/react-reconciler/src/__tests__/ReactTransitionTracing-test.js index 1a2b7c859e779..72397a8446a52 100644 --- a/packages/react-reconciler/src/__tests__/ReactTransitionTracing-test.js +++ b/packages/react-reconciler/src/__tests__/ReactTransitionTracing-test.js @@ -37,6 +37,8 @@ describe('ReactInteractionTracing', () => { .join(', '); } beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactUpdatePriority-test.js b/packages/react-reconciler/src/__tests__/ReactUpdatePriority-test.js index 6128180319b5f..c5de798366334 100644 --- a/packages/react-reconciler/src/__tests__/ReactUpdatePriority-test.js +++ b/packages/react-reconciler/src/__tests__/ReactUpdatePriority-test.js @@ -12,6 +12,8 @@ let assertLog; describe('ReactUpdatePriority', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/ReactUse-test.js b/packages/react-reconciler/src/__tests__/ReactUse-test.js index d66b27c81d477..12e93620b5ded 100644 --- a/packages/react-reconciler/src/__tests__/ReactUse-test.js +++ b/packages/react-reconciler/src/__tests__/ReactUse-test.js @@ -20,6 +20,8 @@ let waitForMicrotasks; describe('ReactUse', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js b/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js index fd7d6c4ef31c6..62ff0e19e6230 100644 --- a/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js +++ b/packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js @@ -17,6 +17,7 @@ let assertLog; describe('StrictEffectsMode', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactTestRenderer = require('react-test-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-reconciler/src/__tests__/useEffectEvent-test.js b/packages/react-reconciler/src/__tests__/useEffectEvent-test.js index f140351a02698..38cdae73f0124 100644 --- a/packages/react-reconciler/src/__tests__/useEffectEvent-test.js +++ b/packages/react-reconciler/src/__tests__/useEffectEvent-test.js @@ -12,6 +12,8 @@ 'use strict'; +import {useInsertionEffect} from 'react'; + describe('useEffectEvent', () => { let React; let ReactNoop; @@ -23,7 +25,6 @@ describe('useEffectEvent', () => { let useEffectEvent; let useEffect; let useLayoutEffect; - let useInsertionEffect; let useMemo; let waitForAll; let assertLog; @@ -42,7 +43,6 @@ describe('useEffectEvent', () => { useEffect = React.useEffect; useLayoutEffect = React.useLayoutEffect; useMemo = React.useMemo; - useInsertionEffect = React.useInsertionEffect; const InternalTestUtils = require('internal-test-utils'); waitForAll = InternalTestUtils.waitForAll; diff --git a/packages/react-reconciler/src/__tests__/useMemoCache-test.js b/packages/react-reconciler/src/__tests__/useMemoCache-test.js index 1eea6bd3394cc..94571df0f9d83 100644 --- a/packages/react-reconciler/src/__tests__/useMemoCache-test.js +++ b/packages/react-reconciler/src/__tests__/useMemoCache-test.js @@ -18,6 +18,8 @@ let ErrorBoundary; describe('useMemoCache()', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); act = require('internal-test-utils').act; diff --git a/packages/react-reconciler/src/__tests__/useSyncExternalStore-test.js b/packages/react-reconciler/src/__tests__/useSyncExternalStore-test.js index 4222bff18368b..67cefa180aa74 100644 --- a/packages/react-reconciler/src/__tests__/useSyncExternalStore-test.js +++ b/packages/react-reconciler/src/__tests__/useSyncExternalStore-test.js @@ -32,6 +32,8 @@ let assertLog; // React DOM versions (16, 17, etc) instead of React Noop. describe('useSyncExternalStore', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-refresh/src/__tests__/ReactFresh-test.js b/packages/react-refresh/src/__tests__/ReactFresh-test.js index 50ea4cb6b7e7d..38b74563c30a7 100644 --- a/packages/react-refresh/src/__tests__/ReactFresh-test.js +++ b/packages/react-refresh/src/__tests__/ReactFresh-test.js @@ -27,6 +27,7 @@ describe('ReactFresh', () => { beforeEach(() => { if (__DEV__) { + jest.resetModules(); React = require('react'); ReactFreshRuntime = require('react-refresh/runtime'); ReactFreshRuntime.injectIntoGlobalHook(global); diff --git a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js index c5eec3f2c4187..ed8c56072a217 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js @@ -29,6 +29,7 @@ describe('ReactFreshIntegration', () => { beforeEach(() => { if (__DEV__) { + jest.resetModules(); React = require('react'); ReactFreshRuntime = require('react-refresh/runtime'); ReactFreshRuntime.injectIntoGlobalHook(global); diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMBrowser-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMBrowser-test.js index 0a214a259fc5f..d797946a3fd3d 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMBrowser-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMBrowser-test.js @@ -21,6 +21,8 @@ let ReactServerDOMClient; describe('ReactFlightDOMBrowser', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMEdge-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMEdge-test.js index 3b736f7f8c3c6..67d25c967f472 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMEdge-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMEdge-test.js @@ -30,6 +30,8 @@ let use; describe('ReactFlightDOMEdge', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMForm-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMForm-test.js index 0ec3bc184275f..3f63222d0ae2d 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMForm-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMForm-test.js @@ -31,6 +31,7 @@ let ReactServerDOMClient; describe('ReactFlightDOMForm', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMNode-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMNode-test.js index 448d5f3e01626..e06ee0a32f950 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMNode-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMNode-test.js @@ -26,6 +26,8 @@ let use; describe('ReactFlightDOMNode', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReply-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReply-test.js index d83237681f207..e47352cfe981d 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReply-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReply-test.js @@ -22,6 +22,7 @@ let ReactServerDOMClient; describe('ReactFlightDOMReply', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReplyEdge-test.js b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReplyEdge-test.js index 99fad128bab53..0cd8605c7e8d6 100644 --- a/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReplyEdge-test.js +++ b/packages/react-server-dom-turbopack/src/__tests__/ReactFlightTurbopackDOMReplyEdge-test.js @@ -22,6 +22,7 @@ let ReactServerDOMClient; describe('ReactFlightDOMReply', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-turbopack/server', () => diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js index b5b66df1b91e1..91ba06dd329b9 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js @@ -42,6 +42,8 @@ describe('ReactFlightDOM', () => { // For this first reset we are going to load the dom-node version of react-server-dom-webpack/server // This can be thought of as essentially being the React Server Components scope with react-server // condition + jest.resetModules(); + JSDOM = require('jsdom').JSDOM; // Simulate the condition resolution diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js index 59e34256f0547..2427317ce2c32 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js @@ -33,6 +33,8 @@ let ReactServerDOM; describe('ReactFlightDOMBrowser', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js index eb2298197dfbb..4b64875c3f89f 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js @@ -31,6 +31,8 @@ let use; describe('ReactFlightDOMEdge', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => 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 604ac14a095ee..dcab688b10c83 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js @@ -36,6 +36,7 @@ let act; describe('ReactFlightDOMForm', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js index 82b35657f26dd..87fc83360018e 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js @@ -26,6 +26,8 @@ let use; describe('ReactFlightDOMNode', () => { beforeEach(() => { + jest.resetModules(); + // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js index 6df1655e5121a..1162d1d0fe738 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js @@ -22,6 +22,7 @@ let ReactServerDOMClient; describe('ReactFlightDOMReply', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js index 9cdc60969a1ba..8e45472956294 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js @@ -22,6 +22,7 @@ let ReactServerDOMClient; describe('ReactFlightDOMReplyEdge', () => { beforeEach(() => { + jest.resetModules(); // Simulate the condition resolution jest.mock('react', () => require('react/react.react-server')); jest.mock('react-server-dom-webpack/server', () => diff --git a/packages/react-server/src/__tests__/ReactServer-test.js b/packages/react-server/src/__tests__/ReactServer-test.js index 0293d3593364f..d827e82de0cac 100644 --- a/packages/react-server/src/__tests__/ReactServer-test.js +++ b/packages/react-server/src/__tests__/ReactServer-test.js @@ -15,6 +15,8 @@ let ReactNoopServer; describe('ReactServer', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactNoopServer = require('react-noop-renderer/server'); }); diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js b/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js index 6de4d6be4a425..0118fa53f3ad3 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js @@ -17,6 +17,7 @@ let waitForAll; describe('ReactTestRenderer', () => { beforeEach(() => { + jest.resetModules(); ReactDOM = require('react-dom'); // Isolate test renderer. diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRendererAct-test.js b/packages/react-test-renderer/src/__tests__/ReactTestRendererAct-test.js index aa89d2fc0b775..2306a895b785c 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRendererAct-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRendererAct-test.js @@ -8,6 +8,7 @@ let assertLog; describe('ReactTestRenderer.act()', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactTestRenderer = require('react-test-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js b/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js index 7c319a2f50aaa..51c7e0a950ddc 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js @@ -18,6 +18,8 @@ let waitFor; describe('ReactTestRendererAsync', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactTestRenderer = require('react-test-renderer'); Scheduler = require('scheduler'); diff --git a/packages/react-test-renderer/src/__tests__/ReactTestRendererTraversal-test.js b/packages/react-test-renderer/src/__tests__/ReactTestRendererTraversal-test.js index cffc417ab775e..d61f0a7c9075a 100644 --- a/packages/react-test-renderer/src/__tests__/ReactTestRendererTraversal-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactTestRendererTraversal-test.js @@ -19,6 +19,7 @@ const View = props => ; describe('ReactTestRendererTraversal', () => { beforeEach(() => { + jest.resetModules(); ReactTestRenderer = require('react-test-renderer'); Context = React.createContext(null); }); diff --git a/packages/react/src/__tests__/ReactChildren-test.js b/packages/react/src/__tests__/ReactChildren-test.js index 4d6a89be8bcce..016e4089d8d3a 100644 --- a/packages/react/src/__tests__/ReactChildren-test.js +++ b/packages/react/src/__tests__/ReactChildren-test.js @@ -15,6 +15,7 @@ describe('ReactChildren', () => { let act; beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react/src/__tests__/ReactContextValidator-test.js b/packages/react/src/__tests__/ReactContextValidator-test.js index 3f0fc6ad419ca..c2c97e0c87a9d 100644 --- a/packages/react/src/__tests__/ReactContextValidator-test.js +++ b/packages/react/src/__tests__/ReactContextValidator-test.js @@ -24,6 +24,8 @@ let act; describe('ReactContextValidator', () => { beforeEach(() => { + jest.resetModules(); + PropTypes = require('prop-types'); React = require('react'); ReactDOMClient = require('react-dom/client'); diff --git a/packages/react/src/__tests__/ReactCreateElement-test.js b/packages/react/src/__tests__/ReactCreateElement-test.js index 7c6a623be1700..6d1a16e3bb145 100644 --- a/packages/react/src/__tests__/ReactCreateElement-test.js +++ b/packages/react/src/__tests__/ReactCreateElement-test.js @@ -20,6 +20,8 @@ describe('ReactCreateElement', () => { let ComponentClass; beforeEach(() => { + jest.resetModules(); + act = require('internal-test-utils').act; React = require('react'); diff --git a/packages/react/src/__tests__/ReactCreateRef-test.js b/packages/react/src/__tests__/ReactCreateRef-test.js index 9e45930ce8454..5c560152b0b26 100644 --- a/packages/react/src/__tests__/ReactCreateRef-test.js +++ b/packages/react/src/__tests__/ReactCreateRef-test.js @@ -14,6 +14,8 @@ let ReactTestRenderer; describe('ReactCreateRef', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactTestRenderer = require('react-test-renderer'); }); diff --git a/packages/react/src/__tests__/ReactFetch-test.js b/packages/react/src/__tests__/ReactFetch-test.js index f89cce08fc138..78fd5d622cd73 100644 --- a/packages/react/src/__tests__/ReactFetch-test.js +++ b/packages/react/src/__tests__/ReactFetch-test.js @@ -40,6 +40,7 @@ let cache; describe('ReactFetch', () => { beforeEach(() => { + jest.resetModules(); fetchCount = 0; global.fetch = fetchMock; diff --git a/packages/react/src/__tests__/ReactFetchEdge-test.js b/packages/react/src/__tests__/ReactFetchEdge-test.js index 67afab7ca3e84..741306a9a2e4a 100644 --- a/packages/react/src/__tests__/ReactFetchEdge-test.js +++ b/packages/react/src/__tests__/ReactFetchEdge-test.js @@ -44,6 +44,7 @@ let use; describe('ReactFetch', () => { beforeEach(() => { + jest.resetModules(); fetchCount = 0; global.fetch = fetchMock; diff --git a/packages/react/src/__tests__/ReactJSXElementValidator-test.js b/packages/react/src/__tests__/ReactJSXElementValidator-test.js index 3b2a9fd83bd1d..b7cdff0ce0aa1 100644 --- a/packages/react/src/__tests__/ReactJSXElementValidator-test.js +++ b/packages/react/src/__tests__/ReactJSXElementValidator-test.js @@ -23,6 +23,8 @@ describe('ReactJSXElementValidator', () => { let RequiredPropComponent; beforeEach(() => { + jest.resetModules(); + PropTypes = require('prop-types'); React = require('react'); ReactDOM = require('react-dom'); diff --git a/packages/react/src/__tests__/ReactJSXRuntime-test.js b/packages/react/src/__tests__/ReactJSXRuntime-test.js index aee64650d1c50..713430fa5ead9 100644 --- a/packages/react/src/__tests__/ReactJSXRuntime-test.js +++ b/packages/react/src/__tests__/ReactJSXRuntime-test.js @@ -22,6 +22,8 @@ let act; // transform that we use in our tests configuration. describe('ReactJSXRuntime', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); JSXRuntime = require('react/jsx-runtime'); JSXDEVRuntime = require('react/jsx-dev-runtime'); diff --git a/packages/react/src/__tests__/ReactJSXTransformIntegration-test.js b/packages/react/src/__tests__/ReactJSXTransformIntegration-test.js index ede9d60261e3f..6f764db3b11ce 100644 --- a/packages/react/src/__tests__/ReactJSXTransformIntegration-test.js +++ b/packages/react/src/__tests__/ReactJSXTransformIntegration-test.js @@ -26,6 +26,8 @@ describe('ReactJSXTransformIntegration', () => { let Component; beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); ReactTestUtils = require('react-dom/test-utils'); diff --git a/packages/react/src/__tests__/ReactStartTransition-test.js b/packages/react/src/__tests__/ReactStartTransition-test.js index b60cb7b6ca1e1..c98372a7c74b7 100644 --- a/packages/react/src/__tests__/ReactStartTransition-test.js +++ b/packages/react/src/__tests__/ReactStartTransition-test.js @@ -19,6 +19,7 @@ const SUSPICIOUS_NUMBER_OF_FIBERS_UPDATED = 10; describe('ReactStartTransition', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactTestRenderer = require('react-test-renderer'); act = require('internal-test-utils').act; diff --git a/packages/react/src/__tests__/ReactStrictMode-test.js b/packages/react/src/__tests__/ReactStrictMode-test.js index 4ccc9a2687175..28dd94ad06ca2 100644 --- a/packages/react/src/__tests__/ReactStrictMode-test.js +++ b/packages/react/src/__tests__/ReactStrictMode-test.js @@ -23,6 +23,7 @@ const ReactFeatureFlags = require('shared/ReactFeatureFlags'); describe('ReactStrictMode', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); @@ -568,6 +569,8 @@ describe('ReactStrictMode', () => { describe('Concurrent Mode', () => { beforeEach(() => { + jest.resetModules(); + React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; @@ -830,6 +833,7 @@ Please update the following components: Parent`, describe('symbol checks', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; @@ -957,6 +961,7 @@ describe('symbol checks', () => { describe('string refs', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); @@ -1042,6 +1047,7 @@ describe('string refs', () => { describe('context legacy', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; @@ -1132,6 +1138,7 @@ describe('context legacy', () => { describe('console logs logging', () => { beforeEach(() => { + jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); act = require('internal-test-utils').act; diff --git a/packages/react/src/__tests__/createReactClassIntegration-test.js b/packages/react/src/__tests__/createReactClassIntegration-test.js index 5c1babb401f7f..dfba4146f443a 100644 --- a/packages/react/src/__tests__/createReactClassIntegration-test.js +++ b/packages/react/src/__tests__/createReactClassIntegration-test.js @@ -18,6 +18,7 @@ let createReactClass; describe('create-react-class-integration', () => { beforeEach(() => { + jest.resetModules(); ({act} = require('internal-test-utils')); PropTypes = require('prop-types'); React = require('react'); diff --git a/packages/react/src/__tests__/forwardRef-test.js b/packages/react/src/__tests__/forwardRef-test.js index ed361d9015a1d..0cfa0031266eb 100644 --- a/packages/react/src/__tests__/forwardRef-test.js +++ b/packages/react/src/__tests__/forwardRef-test.js @@ -16,6 +16,7 @@ describe('forwardRef', () => { let waitForAll; beforeEach(() => { + jest.resetModules(); PropTypes = require('prop-types'); React = require('react'); ReactNoop = require('react-noop-renderer'); diff --git a/packages/scheduler/src/__tests__/Scheduler-test.js b/packages/scheduler/src/__tests__/Scheduler-test.js index 7972876894623..14ef25f3ad4f5 100644 --- a/packages/scheduler/src/__tests__/Scheduler-test.js +++ b/packages/scheduler/src/__tests__/Scheduler-test.js @@ -33,6 +33,7 @@ let NormalPriority; // assumes as little as possible about the order and timing of events. describe('SchedulerBrowser', () => { beforeEach(() => { + jest.resetModules(); runtime = installMockBrowserRuntime(); jest.unmock('scheduler'); diff --git a/packages/scheduler/src/__tests__/SchedulerMock-test.js b/packages/scheduler/src/__tests__/SchedulerMock-test.js index e93af4b29ea33..d71957ef3ebae 100644 --- a/packages/scheduler/src/__tests__/SchedulerMock-test.js +++ b/packages/scheduler/src/__tests__/SchedulerMock-test.js @@ -28,6 +28,7 @@ let waitForPaint; describe('Scheduler', () => { beforeEach(() => { + jest.resetModules(); jest.mock('scheduler', () => require('scheduler/unstable_mock')); Scheduler = require('scheduler'); diff --git a/packages/scheduler/src/__tests__/SchedulerPostTask-test.js b/packages/scheduler/src/__tests__/SchedulerPostTask-test.js index 5b40873406b31..c572ec595bb10 100644 --- a/packages/scheduler/src/__tests__/SchedulerPostTask-test.js +++ b/packages/scheduler/src/__tests__/SchedulerPostTask-test.js @@ -30,6 +30,7 @@ let shouldYield; // and timing of events. describe('SchedulerPostTask', () => { beforeEach(() => { + jest.resetModules(); jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_post_task'), ); diff --git a/packages/scheduler/src/__tests__/SchedulerProfiling-test.js b/packages/scheduler/src/__tests__/SchedulerProfiling-test.js index cf44e6ae244c9..eef602d90ac3d 100644 --- a/packages/scheduler/src/__tests__/SchedulerProfiling-test.js +++ b/packages/scheduler/src/__tests__/SchedulerProfiling-test.js @@ -57,6 +57,7 @@ describe('Scheduler', () => { } beforeEach(() => { + jest.resetModules(); jest.mock('scheduler', () => require('scheduler/unstable_mock')); Scheduler = require('scheduler'); diff --git a/packages/scheduler/src/__tests__/SchedulerSetImmediate-test.js b/packages/scheduler/src/__tests__/SchedulerSetImmediate-test.js index fb41dad71e1f5..52b71b569f415 100644 --- a/packages/scheduler/src/__tests__/SchedulerSetImmediate-test.js +++ b/packages/scheduler/src/__tests__/SchedulerSetImmediate-test.js @@ -32,6 +32,7 @@ let UserBlockingPriority; // assumes as little as possible about the order and timing of events. describe('SchedulerDOMSetImmediate', () => { beforeEach(() => { + jest.resetModules(); runtime = installMockBrowserRuntime(); jest.unmock('scheduler'); diff --git a/packages/scheduler/src/__tests__/SchedulerSetTimeout-test.js b/packages/scheduler/src/__tests__/SchedulerSetTimeout-test.js index 6fb55ed19bc3f..986d329632c27 100644 --- a/packages/scheduler/src/__tests__/SchedulerSetTimeout-test.js +++ b/packages/scheduler/src/__tests__/SchedulerSetTimeout-test.js @@ -20,6 +20,7 @@ describe('SchedulerNoDOM', () => { // Scheduler falls back to a naive implementation using setTimeout. // This is only meant to be used for testing purposes, like with jest's fake timer API. beforeEach(() => { + jest.resetModules(); jest.useFakeTimers(); delete global.setImmediate; delete global.MessageChannel; @@ -99,6 +100,7 @@ describe('SchedulerNoDOM', () => { // See: https://github.com/facebook/react/pull/13088 describe('does not crash non-node SSR environments', () => { it('if setTimeout is undefined', () => { + jest.resetModules(); const originalSetTimeout = global.setTimeout; try { delete global.setTimeout; @@ -112,6 +114,7 @@ describe('does not crash non-node SSR environments', () => { }); it('if clearTimeout is undefined', () => { + jest.resetModules(); const originalClearTimeout = global.clearTimeout; try { delete global.clearTimeout; diff --git a/packages/shared/__tests__/ReactDOMFrameScheduling-test.js b/packages/shared/__tests__/ReactDOMFrameScheduling-test.js index a06e7189557e3..9295dc1010864 100644 --- a/packages/shared/__tests__/ReactDOMFrameScheduling-test.js +++ b/packages/shared/__tests__/ReactDOMFrameScheduling-test.js @@ -11,6 +11,8 @@ describe('ReactDOMFrameScheduling', () => { beforeEach(() => { + jest.resetModules(); + jest.unmock('scheduler'); }); diff --git a/packages/use-subscription/src/__tests__/useSubscription-test.js b/packages/use-subscription/src/__tests__/useSubscription-test.js index 47f59d1e25c14..9c971bd14bbb3 100644 --- a/packages/use-subscription/src/__tests__/useSubscription-test.js +++ b/packages/use-subscription/src/__tests__/useSubscription-test.js @@ -22,6 +22,7 @@ let waitFor; describe('useSubscription', () => { beforeEach(() => { + jest.resetModules(); jest.mock('scheduler', () => require('scheduler/unstable_mock')); useSubscription = require('use-subscription').useSubscription; diff --git a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreNative-test.js b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreNative-test.js index e3bd6c4ac0ca7..fef2d1e76f581 100644 --- a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreNative-test.js +++ b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreNative-test.js @@ -23,6 +23,8 @@ let assertLog; // (Node) environment describe('useSyncExternalStore (userspace shim, server rendering)', () => { beforeEach(() => { + jest.resetModules(); + // Remove useSyncExternalStore from the React imports so that we use the // shim instead. Also removing startTransition, since we use that to detect // outdated 18 alphas that don't yet include useSyncExternalStore. diff --git a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js index 29559bb5079d4..2fe71bf73c528 100644 --- a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js +++ b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js @@ -26,6 +26,8 @@ let assertLog; // of useSyncExternalStore. describe('Shared useSyncExternalStore behavior (shim and built-in)', () => { beforeEach(() => { + jest.resetModules(); + if (gate(flags => flags.enableUseSyncExternalStoreShim)) { // Test the shim against React 17. jest.mock('react', () => { diff --git a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShimServer-test.js b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShimServer-test.js index cf7ed2148fe04..6eacb9a99c606 100644 --- a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShimServer-test.js +++ b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShimServer-test.js @@ -22,6 +22,8 @@ let assertLog; // (Node) environment describe('useSyncExternalStore (userspace shim, server rendering)', () => { beforeEach(() => { + jest.resetModules(); + // Remove useSyncExternalStore from the React imports so that we use the // shim instead. Also removing startTransition, since we use that to detect // outdated 18 alphas that don't yet include useSyncExternalStore. diff --git a/scripts/jest/config.base.js b/scripts/jest/config.base.js index 26c68bfc26b42..a887e66b7dd3c 100644 --- a/scripts/jest/config.base.js +++ b/scripts/jest/config.base.js @@ -6,7 +6,6 @@ module.exports = { '/scripts/rollup/shims/', '/scripts/bench/', ], - resetModules: true, transform: { '.*': require.resolve('./preprocessor.js'), }, From 5d445b50a670d6cdc52943ca4e5ab3422792c57c Mon Sep 17 00:00:00 2001 From: Ricky Date: Tue, 13 Feb 2024 11:48:56 -0500 Subject: [PATCH 3/6] Land enableAsyncActions enableFormActions in www (#28315) --- packages/shared/forks/ReactFeatureFlags.www-dynamic.js | 2 -- packages/shared/forks/ReactFeatureFlags.www.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js index cd073c6429982..a8c873d93b86e 100644 --- a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js @@ -24,8 +24,6 @@ export const forceConcurrentByDefaultForTesting = __VARIANT__; export const enableUnifiedSyncLane = __VARIANT__; export const enableTransitionTracing = __VARIANT__; export const enableDeferRootSchedulingToMicrotask = __VARIANT__; -export const enableAsyncActions = __VARIANT__; -export const enableFormActions = __VARIANT__; export const alwaysThrottleRetries = __VARIANT__; export const enableDO_NOT_USE_disableStrictPassiveEffect = __VARIANT__; export const enableUseDeferredValueInitialArg = __VARIANT__; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 798134ab70c24..2bfba8c3a858f 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -27,8 +27,6 @@ export const { enableRetryLaneExpiration, enableTransitionTracing, enableDeferRootSchedulingToMicrotask, - enableAsyncActions, - enableFormActions, alwaysThrottleRetries, enableDO_NOT_USE_disableStrictPassiveEffect, disableSchedulerTimeoutInWorkLoop, @@ -61,6 +59,8 @@ export const enableUseMemoCacheHook = true; export const enableUseEffectEventHook = true; export const enableClientRenderFallbackOnTextMismatch = false; export const enableFilterEmptyStringAttributesDOM = true; +export const enableFormActions = true; +export const enableAsyncActions = true; // Logs additional User Timing API marks for use with an experimental profiling tool. export const enableSchedulingProfiler: boolean = From 4867a3365e9d2f19c795463caa5a6294c2915269 Mon Sep 17 00:00:00 2001 From: Ricky Date: Tue, 13 Feb 2024 12:15:44 -0500 Subject: [PATCH 4/6] Enable disableJavaScriptURLs for RN (#28306) This is DOM only --- packages/shared/forks/ReactFeatureFlags.native-fb.js | 2 +- packages/shared/forks/ReactFeatureFlags.native-oss.js | 2 +- packages/shared/forks/ReactFeatureFlags.test-renderer.native.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 3990e11a2ac9b..a9e637804426d 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -44,7 +44,7 @@ export const enableBinaryFlight = true; export const enableTaint = true; export const enablePostpone = false; export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; -export const disableJavaScriptURLs = false; +export const disableJavaScriptURLs = true; export const disableCommentsAsDOMContainers = true; export const disableInputAttributeSyncing = false; export const disableIEWorkarounds = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index d29f699abbbde..4ccf5c6aa3219 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -28,7 +28,7 @@ export const enableFormActions = true; // Doesn't affect Native export const enableBinaryFlight = true; export const enableTaint = true; export const enablePostpone = false; -export const disableJavaScriptURLs = false; +export const disableJavaScriptURLs = true; export const disableCommentsAsDOMContainers = true; export const disableInputAttributeSyncing = false; export const disableIEWorkarounds = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index fc53c654b16d9..4390303eeb181 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -28,7 +28,7 @@ export const enableFormActions = true; // Doesn't affect Test Renderer export const enableBinaryFlight = true; export const enableTaint = true; export const enablePostpone = false; -export const disableJavaScriptURLs = false; +export const disableJavaScriptURLs = true; export const disableCommentsAsDOMContainers = true; export const disableInputAttributeSyncing = false; export const disableIEWorkarounds = true; From 0d108f218222d0221cb90ee88a92a66cd9970aab Mon Sep 17 00:00:00 2001 From: Ricky Date: Tue, 13 Feb 2024 12:15:55 -0500 Subject: [PATCH 5/6] Enable more noop RN flags (#28307) --- packages/shared/forks/ReactFeatureFlags.native-fb.js | 2 +- packages/shared/forks/ReactFeatureFlags.native-oss.js | 4 ++-- packages/shared/forks/ReactFeatureFlags.test-renderer.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index a9e637804426d..3a95817810fac 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -88,7 +88,7 @@ export const enableFloat = true; export const useModernStrictMode = false; export const enableDO_NOT_USE_disableStrictPassiveEffect = false; -export const enableFizzExternalRuntime = false; +export const enableFizzExternalRuntime = true; export const enableAsyncActions = false; export const enableUseDeferredValueInitialArg = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 4ccf5c6aa3219..78c591c0aebf1 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -22,7 +22,7 @@ export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = __PROFILE__; export const enableCache = false; export const enableLegacyCache = false; -export const enableCacheElement = false; +export const enableCacheElement = true; export const enableFetchInstrumentation = false; export const enableFormActions = true; // Doesn't affect Native export const enableBinaryFlight = true; @@ -74,7 +74,7 @@ export const enableFloat = true; export const useModernStrictMode = false; export const enableDO_NOT_USE_disableStrictPassiveEffect = false; -export const enableFizzExternalRuntime = false; +export const enableFizzExternalRuntime = true; export const enableDeferRootSchedulingToMicrotask = false; export const enableInfiniteRenderLoopDetection = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 6577d2a338893..93018e5c091da 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -74,7 +74,7 @@ export const enableFloat = true; export const useModernStrictMode = false; export const enableDO_NOT_USE_disableStrictPassiveEffect = false; -export const enableFizzExternalRuntime = false; +export const enableFizzExternalRuntime = true; export const enableDeferRootSchedulingToMicrotask = true; export const enableAsyncActions = true; From dc3178151b8cb0359e5c36b8ed57458b807ae8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 13 Feb 2024 12:54:06 -0500 Subject: [PATCH 6/6] Add ignoreList to our source maps (#28310) All our sources are considered third party and should be hidden in stack traces unless expanded. Our internals aren't actionable anyway. This doesn't really do much without tooling that actually forwards this to new generated source maps, in which case they probably just add them to ignorelist anyway. --- scripts/rollup/build.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 0a2a584c5a5a7..d6f4155194af3 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -575,6 +575,9 @@ function getPlugins( sourcemapAfterClosure.sources = [preMinifiedFilename]; sourcemapAfterClosure.file = filename; + // All our code is considered "third-party" and should be ignored by default. + sourcemapAfterClosure.ignoreList = [0]; + // We'll write the pre-minified source to disk as a separate file. // Because it sits on disk, there's no need to have it in the `sourcesContent` array. // That also makes the file easier to read, and available for use by scripts.