Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ describe('ReactIs', () => {
expect(ReactIs.isValidElementType(Context.Provider)).toEqual(true);
expect(ReactIs.isValidElementType(Context.Consumer)).toEqual(true);
if (!ReactFeatureFlags.disableCreateFactory) {
expect(ReactIs.isValidElementType(React.createFactory('div'))).toEqual(
true,
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);
Expand Down
12 changes: 11 additions & 1 deletion packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,21 @@ export function createElementWithValidation(type, props, children) {
return element;
}

let didWarnAboutDeprecatedCreateFactory = false;

export function createFactoryWithValidation(type) {
const validatedFactory = createElementWithValidation.bind(null, type);
validatedFactory.type = type;
// Legacy hook: remove it
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(validatedFactory, 'type', {
enumerable: false,
get: function() {
Expand Down
22 changes: 20 additions & 2 deletions packages/react/src/__tests__/ReactElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,16 @@ describe('ReactElement', () => {
expect(React.isValidElement({})).toEqual(false);
expect(React.isValidElement('string')).toEqual(false);
if (!ReactFeatureFlags.disableCreateFactory) {
expect(React.isValidElement(React.createFactory('div'))).toEqual(false);
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(React.isValidElement(factory)).toEqual(false);
}
expect(React.isValidElement(Component)).toEqual(false);
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
Expand Down Expand Up @@ -473,7 +482,16 @@ describe('ReactElement', () => {
expect(React.isValidElement({})).toEqual(false);
expect(React.isValidElement('string')).toEqual(false);
if (!ReactFeatureFlags.disableCreateFactory) {
expect(React.isValidElement(React.createFactory('div'))).toEqual(false);
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(React.isValidElement(factory)).toEqual(false);
}
expect(React.isValidElement(Component)).toEqual(false);
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
Expand Down
22 changes: 20 additions & 2 deletions packages/react/src/__tests__/ReactElementJSX-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ describe('ReactElement.jsx', () => {
expect(React.isValidElement({})).toEqual(false);
expect(React.isValidElement('string')).toEqual(false);
if (!ReactFeatureFlags.disableCreateFactory) {
expect(React.isValidElement(React.createFactory('div'))).toEqual(false);
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(React.isValidElement(factory)).toEqual(false);
}
expect(React.isValidElement(Component)).toEqual(false);
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
Expand Down Expand Up @@ -301,7 +310,16 @@ describe('ReactElement.jsx', () => {
expect(React.isValidElement({})).toEqual(false);
expect(React.isValidElement('string')).toEqual(false);
if (!ReactFeatureFlags.disableCreateFactory) {
expect(React.isValidElement(React.createFactory('div'))).toEqual(false);
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(React.isValidElement(factory)).toEqual(false);
}
expect(React.isValidElement(Component)).toEqual(false);
expect(React.isValidElement({type: 'div', props: {}})).toEqual(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,17 @@ describe('ReactElementValidator', () => {
return <div />;
}

let TestFactory = React.createFactory(TestComponent);
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(
Expand Down