Skip to content

Commit 0fce6bb

Browse files
authored
[cleanup] remove feature flags warnAboutDefaultPropsOnFunctionComponents and warnAboutStringRefs (#25980)
These feature flags are fully rolled out and easy to clean up. Let's remove them!
1 parent 7002a67 commit 0fce6bb

20 files changed

+111
-225
lines changed

packages/react-dom/src/__tests__/ReactComponent-test.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
let React;
1313
let ReactDOM;
1414
let ReactDOMServer;
15-
let ReactFeatureFlags;
1615
let ReactTestUtils;
1716

1817
describe('ReactComponent', () => {
@@ -22,7 +21,6 @@ describe('ReactComponent', () => {
2221
React = require('react');
2322
ReactDOM = require('react-dom');
2423
ReactDOMServer = require('react-dom/server');
25-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
2624
ReactTestUtils = require('react-dom/test-utils');
2725
});
2826

@@ -137,24 +135,20 @@ describe('ReactComponent', () => {
137135

138136
expect(() => {
139137
ReactTestUtils.renderIntoDocument(<Component />);
140-
}).toErrorDev(
141-
ReactFeatureFlags.warnAboutStringRefs
142-
? [
143-
'Warning: Component "div" contains the string ref "inner". ' +
144-
'Support for string refs will be removed in a future major release. ' +
145-
'We recommend using useRef() or createRef() instead. ' +
146-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
147-
' in div (at **)\n' +
148-
' in Wrapper (at **)\n' +
149-
' in Component (at **)',
150-
'Warning: Component "Component" contains the string ref "outer". ' +
151-
'Support for string refs will be removed in a future major release. ' +
152-
'We recommend using useRef() or createRef() instead. ' +
153-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
154-
' in Component (at **)',
155-
]
156-
: [],
157-
);
138+
}).toErrorDev([
139+
'Warning: Component "div" contains the string ref "inner". ' +
140+
'Support for string refs will be removed in a future major release. ' +
141+
'We recommend using useRef() or createRef() instead. ' +
142+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
143+
' in div (at **)\n' +
144+
' in Wrapper (at **)\n' +
145+
' in Component (at **)',
146+
'Warning: Component "Component" contains the string ref "outer". ' +
147+
'Support for string refs will be removed in a future major release. ' +
148+
'We recommend using useRef() or createRef() instead. ' +
149+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
150+
' in Component (at **)',
151+
]);
158152
});
159153

160154
it('should not have string refs on unmounted components', () => {

packages/react-dom/src/__tests__/ReactDOMServerIntegrationRefs-test.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio
1414
let React;
1515
let ReactDOM;
1616
let ReactDOMServer;
17-
let ReactFeatureFlags;
1817
let ReactTestUtils;
1918

2019
function initModules() {
@@ -23,7 +22,6 @@ function initModules() {
2322
React = require('react');
2423
ReactDOM = require('react-dom');
2524
ReactDOMServer = require('react-dom/server');
26-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
2725
ReactTestUtils = require('react-dom/test-utils');
2826

2927
// Make them available to the helpers.
@@ -99,17 +97,13 @@ describe('ReactDOMServerIntegration', () => {
9997
root,
10098
true,
10199
);
102-
}).toErrorDev(
103-
ReactFeatureFlags.warnAboutStringRefs
104-
? [
105-
'Warning: Component "RefsComponent" contains the string ref "myDiv". ' +
106-
'Support for string refs will be removed in a future major release. ' +
107-
'We recommend using useRef() or createRef() instead. ' +
108-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
109-
' in RefsComponent (at **)',
110-
]
111-
: [],
112-
);
100+
}).toErrorDev([
101+
'Warning: Component "RefsComponent" contains the string ref "myDiv". ' +
102+
'Support for string refs will be removed in a future major release. ' +
103+
'We recommend using useRef() or createRef() instead. ' +
104+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
105+
' in RefsComponent (at **)',
106+
]);
113107
expect(component.refs.myDiv).toBe(root.firstChild);
114108
});
115109
});

packages/react-dom/src/__tests__/refs-test.js

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,24 @@ describe('reactiverefs', () => {
123123
let testRefsComponent;
124124
expect(() => {
125125
testRefsComponent = ReactDOM.render(<TestRefsComponent />, container);
126-
}).toErrorDev(
127-
ReactFeatureFlags.warnAboutStringRefs
128-
? [
129-
'Warning: Component "div" contains the string ref "resetDiv". ' +
130-
'Support for string refs will be removed in a future major release. ' +
131-
'We recommend using useRef() or createRef() instead. ' +
132-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
133-
' in div (at **)\n' +
134-
' in TestRefsComponent (at **)',
135-
'Warning: Component "span" contains the string ref "clickLog0". ' +
136-
'Support for string refs will be removed in a future major release. ' +
137-
'We recommend using useRef() or createRef() instead. ' +
138-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
139-
' in span (at **)\n' +
140-
' in ClickCounter (at **)\n' +
141-
' in div (at **)\n' +
142-
' in GeneralContainerComponent (at **)\n' +
143-
' in div (at **)\n' +
144-
' in TestRefsComponent (at **)',
145-
]
146-
: [],
147-
);
126+
}).toErrorDev([
127+
'Warning: Component "div" contains the string ref "resetDiv". ' +
128+
'Support for string refs will be removed in a future major release. ' +
129+
'We recommend using useRef() or createRef() instead. ' +
130+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
131+
' in div (at **)\n' +
132+
' in TestRefsComponent (at **)',
133+
'Warning: Component "span" contains the string ref "clickLog0". ' +
134+
'Support for string refs will be removed in a future major release. ' +
135+
'We recommend using useRef() or createRef() instead. ' +
136+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
137+
' in span (at **)\n' +
138+
' in ClickCounter (at **)\n' +
139+
' in div (at **)\n' +
140+
' in GeneralContainerComponent (at **)\n' +
141+
' in div (at **)\n' +
142+
' in TestRefsComponent (at **)',
143+
]);
148144

149145
expect(testRefsComponent instanceof TestRefsComponent).toBe(true);
150146

@@ -349,17 +345,13 @@ describe('ref swapping', () => {
349345
let a;
350346
expect(() => {
351347
a = ReactTestUtils.renderIntoDocument(<A />);
352-
}).toErrorDev(
353-
ReactFeatureFlags.warnAboutStringRefs
354-
? [
355-
'Warning: Component "A" contains the string ref "1". ' +
356-
'Support for string refs will be removed in a future major release. ' +
357-
'We recommend using useRef() or createRef() instead. ' +
358-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
359-
' in A (at **)',
360-
]
361-
: [],
362-
);
348+
}).toErrorDev([
349+
'Warning: Component "A" contains the string ref "1". ' +
350+
'Support for string refs will be removed in a future major release. ' +
351+
'We recommend using useRef() or createRef() instead. ' +
352+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
353+
' in A (at **)',
354+
]);
363355
expect(a.refs[1].nodeName).toBe('DIV');
364356
});
365357

@@ -546,18 +538,14 @@ describe('strings refs across renderers', () => {
546538
let inst;
547539
expect(() => {
548540
inst = ReactDOM.render(<Parent />, div1);
549-
}).toErrorDev(
550-
ReactFeatureFlags.warnAboutStringRefs
551-
? [
552-
'Warning: Component "Indirection" contains the string ref "child1". ' +
553-
'Support for string refs will be removed in a future major release. ' +
554-
'We recommend using useRef() or createRef() instead. ' +
555-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
556-
' in Indirection (at **)\n' +
557-
' in Parent (at **)',
558-
]
559-
: [],
560-
);
541+
}).toErrorDev([
542+
'Warning: Component "Indirection" contains the string ref "child1". ' +
543+
'Support for string refs will be removed in a future major release. ' +
544+
'We recommend using useRef() or createRef() instead. ' +
545+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
546+
' in Indirection (at **)\n' +
547+
' in Parent (at **)',
548+
]);
561549

562550
// Only the first ref has rendered yet.
563551
expect(inst.refs.child1.tagName).toBe('DIV');
@@ -567,14 +555,12 @@ describe('strings refs across renderers', () => {
567555
// Now both refs should be rendered.
568556
ReactDOM.render(<Parent />, div1);
569557
}).toErrorDev(
570-
ReactFeatureFlags.warnAboutStringRefs
571-
? [
572-
'Warning: Component "Root" contains the string ref "child2". ' +
573-
'Support for string refs will be removed in a future major release. ' +
574-
'We recommend using useRef() or createRef() instead. ' +
575-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',
576-
]
577-
: [],
558+
[
559+
'Warning: Component "Root" contains the string ref "child2". ' +
560+
'Support for string refs will be removed in a future major release. ' +
561+
'We recommend using useRef() or createRef() instead. ' +
562+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',
563+
],
578564
{withoutStack: true},
579565
);
580566
expect(inst.refs.child1.tagName).toBe('DIV');

packages/react-reconciler/src/ReactChildFiber.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
} from 'shared/ReactSymbols';
2929
import {ClassComponent, HostText, HostPortal, Fragment} from './ReactWorkTags';
3030
import isArray from 'shared/isArray';
31-
import {warnAboutStringRefs} from 'shared/ReactFeatureFlags';
3231
import {checkPropStringCoercion} from 'shared/CheckStringCoercion';
3332

3433
import {
@@ -40,7 +39,6 @@ import {
4039
createFiberFromPortal,
4140
} from './ReactFiber';
4241
import {isCompatibleFamilyForHotReloading} from './ReactFiberHotReloading';
43-
import {StrictLegacyMode} from './ReactTypeOfMode';
4442
import {getIsHydrating} from './ReactFiberHydrationContext';
4543
import {pushTreeFork} from './ReactFiberTreeContext';
4644

@@ -113,10 +111,7 @@ function coerceRef(
113111
typeof mixedRef !== 'object'
114112
) {
115113
if (__DEV__) {
116-
// TODO: Clean this up once we turn on the string ref warning for
117-
// everyone, because the strict mode case will no longer be relevant
118114
if (
119-
(returnFiber.mode & StrictLegacyMode || warnAboutStringRefs) &&
120115
// We warn in ReactElement.js if owner and self are equal for string refs
121116
// because these cannot be automatically converted to an arrow function
122117
// using a codemod. Therefore, we don't have to warn about string refs again.
@@ -138,26 +133,15 @@ function coerceRef(
138133
const componentName =
139134
getComponentNameFromFiber(returnFiber) || 'Component';
140135
if (!didWarnAboutStringRefs[componentName]) {
141-
if (warnAboutStringRefs) {
142-
console.error(
143-
'Component "%s" contains the string ref "%s". Support for string refs ' +
144-
'will be removed in a future major release. We recommend using ' +
145-
'useRef() or createRef() instead. ' +
146-
'Learn more about using refs safely here: ' +
147-
'https://reactjs.org/link/strict-mode-string-ref',
148-
componentName,
149-
mixedRef,
150-
);
151-
} else {
152-
console.error(
153-
'A string ref, "%s", has been found within a strict mode tree. ' +
154-
'String refs are a source of potential bugs and should be avoided. ' +
155-
'We recommend using useRef() or createRef() instead. ' +
156-
'Learn more about using refs safely here: ' +
157-
'https://reactjs.org/link/strict-mode-string-ref',
158-
mixedRef,
159-
);
160-
}
136+
console.error(
137+
'Component "%s" contains the string ref "%s". Support for string refs ' +
138+
'will be removed in a future major release. We recommend using ' +
139+
'useRef() or createRef() instead. ' +
140+
'Learn more about using refs safely here: ' +
141+
'https://reactjs.org/link/strict-mode-string-ref',
142+
componentName,
143+
mixedRef,
144+
);
161145
didWarnAboutStringRefs[componentName] = true;
162146
}
163147
}

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import {
9797
disableModulePatternComponents,
9898
enableProfilerCommitHooks,
9999
enableProfilerTimer,
100-
warnAboutDefaultPropsOnFunctionComponents,
101100
enableScopeAPI,
102101
enableCache,
103102
enableLazyContextPropagation,
@@ -506,10 +505,7 @@ function updateMemoComponent(
506505
getComponentNameFromType(type),
507506
);
508507
}
509-
if (
510-
warnAboutDefaultPropsOnFunctionComponents &&
511-
Component.defaultProps !== undefined
512-
) {
508+
if (Component.defaultProps !== undefined) {
513509
const componentName = getComponentNameFromType(type) || 'Unknown';
514510
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
515511
console.error(
@@ -2058,10 +2054,7 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
20582054
}
20592055
}
20602056

2061-
if (
2062-
warnAboutDefaultPropsOnFunctionComponents &&
2063-
Component.defaultProps !== undefined
2064-
) {
2057+
if (Component.defaultProps !== undefined) {
20652058
const componentName = getComponentNameFromType(Component) || 'Unknown';
20662059

20672060
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {

packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
let React;
14-
let ReactFeatureFlags;
1514
let ReactNoop;
1615
let Scheduler;
1716

@@ -20,7 +19,6 @@ describe('ReactIncrementalSideEffects', () => {
2019
jest.resetModules();
2120

2221
React = require('react');
23-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
2422
ReactNoop = require('react-noop-renderer');
2523
Scheduler = require('scheduler');
2624
});
@@ -1310,17 +1308,13 @@ describe('ReactIncrementalSideEffects', () => {
13101308
ReactNoop.render(<Foo />);
13111309
expect(() => {
13121310
expect(Scheduler).toFlushWithoutYielding();
1313-
}).toErrorDev(
1314-
ReactFeatureFlags.warnAboutStringRefs
1315-
? [
1316-
'Warning: Component "Foo" contains the string ref "bar". ' +
1317-
'Support for string refs will be removed in a future major release. ' +
1318-
'We recommend using useRef() or createRef() instead. ' +
1319-
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
1320-
' in Foo (at **)',
1321-
]
1322-
: [],
1323-
);
1311+
}).toErrorDev([
1312+
'Warning: Component "Foo" contains the string ref "bar". ' +
1313+
'Support for string refs will be removed in a future major release. ' +
1314+
'We recommend using useRef() or createRef() instead. ' +
1315+
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
1316+
' in Foo (at **)',
1317+
]);
13241318
expect(fooInstance.refs.bar.test).toEqual('test');
13251319
});
13261320
});

packages/react-server/src/ReactFizzServer.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
129129
import {
130130
disableLegacyContext,
131131
disableModulePatternComponents,
132-
warnAboutDefaultPropsOnFunctionComponents,
133132
enableScopeAPI,
134133
enableSuspenseAvoidThisFallbackFizz,
135134
enableFloat,
@@ -949,10 +948,7 @@ function validateFunctionComponentInDev(Component: any): void {
949948
}
950949
}
951950

952-
if (
953-
warnAboutDefaultPropsOnFunctionComponents &&
954-
Component.defaultProps !== undefined
955-
) {
951+
if (Component.defaultProps !== undefined) {
956952
const componentName = getComponentNameFromType(Component) || 'Unknown';
957953

958954
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {

0 commit comments

Comments
 (0)