From f3681239c846b9bd4b9dcc4be6193fb0eaff9b49 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Wed, 6 Dec 2023 10:36:16 -0500 Subject: [PATCH] Remove React.createFactory --- packages/react-is/README.md | 1 - .../react-is/src/__tests__/ReactIs-test.js | 12 ------ packages/react/index.classic.fb.js | 1 - packages/react/index.experimental.js | 1 - packages/react/index.js | 1 - packages/react/index.stable.js | 1 - packages/react/src/ReactClient.js | 4 -- .../ReactElementValidator-test.internal.js | 28 ------------ packages/react/src/jsx/ReactJSXElement.js | 43 ------------------- 9 files changed, 92 deletions(-) diff --git a/packages/react-is/README.md b/packages/react-is/README.md index d255977618178..c446e89c6b0fe 100644 --- a/packages/react-is/README.md +++ b/packages/react-is/README.md @@ -40,7 +40,6 @@ ReactIs.isValidElementType(FunctionComponent); // true ReactIs.isValidElementType(ForwardRefComponent); // true ReactIs.isValidElementType(Context.Provider); // true ReactIs.isValidElementType(Context.Consumer); // true -ReactIs.isValidElementType(React.createFactory("div")); // true ``` ### Determining an Element's Type diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index 5b63eebd529fd..f9d9dc923cc23 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -67,18 +67,6 @@ describe('ReactIs', () => { expect(ReactIs.isValidElementType(MemoComponent)).toEqual(true); expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true); expect(ReactIs.isValidElementType(Context.Consumer)).toEqual(true); - if (!__EXPERIMENTAL__) { - let factory; - expect(() => { - factory = React.createFactory('div'); - }).toWarnDev( - 'Warning: React.createFactory() is deprecated and will be removed in a ' + - 'future major release. Consider using JSX or use React.createElement() ' + - 'directly instead.', - {withoutStack: true}, - ); - expect(ReactIs.isValidElementType(factory)).toEqual(true); - } expect(ReactIs.isValidElementType(React.Fragment)).toEqual(true); expect(ReactIs.isValidElementType(React.StrictMode)).toEqual(true); expect(ReactIs.isValidElementType(React.Suspense)).toEqual(true); diff --git a/packages/react/index.classic.fb.js b/packages/react/index.classic.fb.js index 7c84775bb6cc3..b51f0ee3bc0dd 100644 --- a/packages/react/index.classic.fb.js +++ b/packages/react/index.classic.fb.js @@ -20,7 +20,6 @@ export { cloneElement, createContext, createElement, - createFactory, createRef, use, forwardRef, diff --git a/packages/react/index.experimental.js b/packages/react/index.experimental.js index dcb695e438a19..23280b774fa00 100644 --- a/packages/react/index.experimental.js +++ b/packages/react/index.experimental.js @@ -20,7 +20,6 @@ export { cloneElement, createContext, createElement, - createFactory, createRef, use, forwardRef, diff --git a/packages/react/index.js b/packages/react/index.js index ac3b45c3a7ca8..387dbb5f4e79d 100644 --- a/packages/react/index.js +++ b/packages/react/index.js @@ -41,7 +41,6 @@ export { cloneElement, createContext, createElement, - createFactory, createRef, use, forwardRef, diff --git a/packages/react/index.stable.js b/packages/react/index.stable.js index 2997a62b4a44a..274c08fec435f 100644 --- a/packages/react/index.stable.js +++ b/packages/react/index.stable.js @@ -20,7 +20,6 @@ export { cloneElement, createContext, createElement, - createFactory, createRef, use, forwardRef, diff --git a/packages/react/src/ReactClient.js b/packages/react/src/ReactClient.js index ff988a2a2cf3d..9e5af26381fdc 100644 --- a/packages/react/src/ReactClient.js +++ b/packages/react/src/ReactClient.js @@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef'; import {forEach, map, count, toArray, only} from './ReactChildren'; import { createElement, - createFactory, cloneElement, isValidElement, } from './jsx/ReactJSXElement'; @@ -61,7 +60,6 @@ import { useMemoCache, useOptimistic, } from './ReactHooks'; - import ReactSharedInternals from './ReactSharedInternalsClient'; import {startTransition} from './ReactStartTransition'; import {act} from './ReactAct'; @@ -109,8 +107,6 @@ export { isValidElement, ReactVersion as version, ReactSharedInternals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - // Deprecated behind disableCreateFactory - createFactory, // Concurrent Mode useTransition, startTransition, diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index b1d7257ccdb10..d3e2ed78e5ba6 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -331,34 +331,6 @@ describe('ReactElementValidator', () => { ); }); - if (!__EXPERIMENTAL__) { - it('should warn when accessing .type on an element factory', () => { - function TestComponent() { - return
; - } - - let TestFactory; - - expect(() => { - TestFactory = React.createFactory(TestComponent); - }).toWarnDev( - 'Warning: React.createFactory() is deprecated and will be removed in a ' + - 'future major release. Consider using JSX or use React.createElement() ' + - 'directly instead.', - {withoutStack: true}, - ); - - expect(() => TestFactory.type).toWarnDev( - 'Warning: Factory.type is deprecated. Access the class directly before ' + - 'passing it to createFactory.', - {withoutStack: true}, - ); - - // Warn once, not again - expect(TestFactory.type).toBe(TestComponent); - }); - } - it('does not warn when using DOM node as children', async () => { class DOMContainer extends React.Component { ref; diff --git a/packages/react/src/jsx/ReactJSXElement.js b/packages/react/src/jsx/ReactJSXElement.js index bf455995aa762..b716e0bc08f7c 100644 --- a/packages/react/src/jsx/ReactJSXElement.js +++ b/packages/react/src/jsx/ReactJSXElement.js @@ -757,49 +757,6 @@ export function createElement(type, config, children) { return element; } -let didWarnAboutDeprecatedCreateFactory = false; - -/** - * Return a function that produces ReactElements of a given type. - * See https://reactjs.org/docs/react-api.html#createfactory - */ -export function createFactory(type) { - const factory = createElement.bind(null, type); - // Expose the type on the factory and the prototype so that it can be - // easily accessed on elements. E.g. `.type === Foo`. - // This should not be named `constructor` since this may not be the function - // that created the element, and it may not even be a constructor. - // Legacy hook: remove it - factory.type = type; - - if (__DEV__) { - if (!didWarnAboutDeprecatedCreateFactory) { - didWarnAboutDeprecatedCreateFactory = true; - console.warn( - 'React.createFactory() is deprecated and will be removed in ' + - 'a future major release. Consider using JSX ' + - 'or use React.createElement() directly instead.', - ); - } - // Legacy hook: remove it - Object.defineProperty(factory, 'type', { - enumerable: false, - get: function () { - console.warn( - 'Factory.type is deprecated. Access the class directly ' + - 'before passing it to createFactory.', - ); - Object.defineProperty(this, 'type', { - value: type, - }); - return type; - }, - }); - } - - return factory; -} - export function cloneAndReplaceKey(oldElement, newKey) { return ReactElement( oldElement.type,