diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js index 40ae0b682231b..2202c8bf86e47 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContextDisabled-test.internal.js @@ -34,8 +34,7 @@ function initModules() { }; } -const {resetModules, itRenders, clientRenderOnBadMarkup} = - ReactDOMServerIntegrationUtils(initModules); +const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules); function formatValue(val) { if (val === null) { @@ -105,7 +104,7 @@ describe('ReactDOMServerIntegrationLegacyContextDisabled', () => { , - render === clientRenderOnBadMarkup ? 4 : 3, + 3, ); expect(e.textContent).toBe('{}undefinedundefined'); expect(lifecycleContextLog).toEqual([]); diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.js b/packages/react-reconciler/src/ReactFiberClassComponent.js index b1055c01613f9..4f7ef8530a908 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.js @@ -82,6 +82,8 @@ let didWarnAboutLegacyLifecyclesAndDerivedState; let didWarnAboutUndefinedDerivedState; let didWarnAboutDirectlyAssigningPropsToState; let didWarnAboutContextTypeAndContextTypes; +let didWarnAboutContextTypes; +let didWarnAboutChildContextTypes; let didWarnAboutInvalidateContextType; let didWarnOnInvalidCallback; @@ -93,6 +95,8 @@ if (__DEV__) { didWarnAboutDirectlyAssigningPropsToState = new Set(); didWarnAboutUndefinedDerivedState = new Set(); didWarnAboutContextTypeAndContextTypes = new Set(); + didWarnAboutContextTypes = new Set(); + didWarnAboutChildContextTypes = new Set(); didWarnAboutInvalidateContextType = new Set(); didWarnOnInvalidCallback = new Set(); @@ -385,14 +389,16 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } if (disableLegacyContext) { - if (ctor.childContextTypes) { + if (ctor.childContextTypes && !didWarnAboutChildContextTypes.has(ctor)) { + didWarnAboutChildContextTypes.add(ctor); console.error( '%s uses the legacy childContextTypes API which was removed in React 19. ' + 'Use React.createContext() instead.', name, ); } - if (ctor.contextTypes) { + if (ctor.contextTypes && !didWarnAboutContextTypes.has(ctor)) { + didWarnAboutContextTypes.add(ctor); console.error( '%s uses the legacy contextTypes API which was removed in React 19. ' + 'Use React.createContext() with static contextType instead.', diff --git a/packages/react-server/src/ReactFizzClassComponent.js b/packages/react-server/src/ReactFizzClassComponent.js index 61e48d1afd0c9..6ef87f100b57d 100644 --- a/packages/react-server/src/ReactFizzClassComponent.js +++ b/packages/react-server/src/ReactFizzClassComponent.js @@ -26,6 +26,8 @@ let didWarnAboutLegacyLifecyclesAndDerivedState; let didWarnAboutUndefinedDerivedState; let didWarnAboutDirectlyAssigningPropsToState; let didWarnAboutContextTypeAndContextTypes; +let didWarnAboutContextTypes; +let didWarnAboutChildContextTypes; let didWarnAboutInvalidateContextType; let didWarnOnInvalidCallback; @@ -36,6 +38,8 @@ if (__DEV__) { didWarnAboutDirectlyAssigningPropsToState = new Set(); didWarnAboutUndefinedDerivedState = new Set(); didWarnAboutContextTypeAndContextTypes = new Set(); + didWarnAboutContextTypes = new Set(); + didWarnAboutChildContextTypes = new Set(); didWarnAboutInvalidateContextType = new Set(); didWarnOnInvalidCallback = new Set(); } @@ -362,14 +366,16 @@ function checkClassInstance(instance: any, ctor: any, newProps: any) { } if (disableLegacyContext) { - if (ctor.childContextTypes) { + if (ctor.childContextTypes && !didWarnAboutChildContextTypes.has(ctor)) { + didWarnAboutChildContextTypes.add(ctor); console.error( '%s uses the legacy childContextTypes API which was removed in React 19. ' + 'Use React.createContext() instead.', name, ); } - if (ctor.contextTypes) { + if (ctor.contextTypes && !didWarnAboutContextTypes.has(ctor)) { + didWarnAboutContextTypes.add(ctor); console.error( '%s uses the legacy contextTypes API which was removed in React 19. ' + 'Use React.createContext() with static contextType instead.',