Skip to content

Commit

Permalink
Remove React.createFactory (#27798)
Browse files Browse the repository at this point in the history
`React.createFactory` has been long deprecated. This removes it for the
next release.
  • Loading branch information
kassens authored Mar 29, 2024
1 parent 13f3543 commit 2aed507
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 92 deletions.
1 change: 0 additions & 1 deletion packages/react-is/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export {
cloneElement,
createContext,
createElement,
createFactory,
createRef,
use,
forwardRef,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export {
cloneElement,
createContext,
createElement,
createFactory,
createRef,
use,
forwardRef,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export {
cloneElement,
createContext,
createElement,
createFactory,
createRef,
use,
forwardRef,
Expand Down
1 change: 0 additions & 1 deletion packages/react/index.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export {
cloneElement,
createContext,
createElement,
createFactory,
createRef,
use,
forwardRef,
Expand Down
4 changes: 0 additions & 4 deletions packages/react/src/ReactClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {createRef} from './ReactCreateRef';
import {forEach, map, count, toArray, only} from './ReactChildren';
import {
createElement,
createFactory,
cloneElement,
isValidElement,
} from './jsx/ReactJSXElement';
Expand Down Expand Up @@ -62,7 +61,6 @@ import {
useOptimistic,
useActionState,
} from './ReactHooks';

import ReactSharedInternals from './ReactSharedInternalsClient';
import {startTransition} from './ReactStartTransition';
import {act} from './ReactAct';
Expand Down Expand Up @@ -111,8 +109,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,34 +331,6 @@ describe('ReactElementValidator', () => {
);
});

if (!__EXPERIMENTAL__) {
it('should warn when accessing .type on an element factory', () => {
function TestComponent() {
return <div />;
}

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;
Expand Down
43 changes: 0 additions & 43 deletions packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<Foo />.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,
Expand Down

0 comments on commit 2aed507

Please sign in to comment.