Skip to content

Commit a5b2215

Browse files
authored
Warn if renderSubtreeIntoContainer is called (#23355)
We already warn for all the other legacy APIs. Forgot to enable this one.
1 parent 52c393b commit a5b2215

12 files changed

+57
-51
lines changed

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

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const ReactTestUtils = require('react-dom/test-utils');
1616
const renderSubtreeIntoContainer = require('react-dom')
1717
.unstable_renderSubtreeIntoContainer;
1818

19-
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
20-
2119
describe('renderSubtreeIntoContainer', () => {
2220
it('should pass context when rendering subtree elsewhere', () => {
2321
const portal = document.createElement('div');
@@ -48,18 +46,13 @@ describe('renderSubtreeIntoContainer', () => {
4846
}
4947

5048
componentDidMount() {
51-
if (ReactFeatureFlags.warnUnstableRenderSubtreeIntoContainer) {
52-
expect(
53-
function() {
54-
renderSubtreeIntoContainer(this, <Component />, portal);
55-
}.bind(this),
56-
).toWarnDev(
57-
'ReactDOM.unstable_renderSubtreeIntoContainer() is deprecated and ' +
58-
'will be removed in a future major release. Consider using React Portals instead.',
59-
);
60-
} else {
61-
renderSubtreeIntoContainer(this, <Component />, portal);
62-
}
49+
expect(
50+
function() {
51+
renderSubtreeIntoContainer(this, <Component />, portal);
52+
}.bind(this),
53+
).toErrorDev(
54+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
55+
);
6356
}
6457
}
6558

@@ -144,11 +137,19 @@ describe('renderSubtreeIntoContainer', () => {
144137
}
145138

146139
componentDidMount() {
147-
renderSubtreeIntoContainer(this, <Component />, portal);
140+
expect(() => {
141+
renderSubtreeIntoContainer(this, <Component />, portal);
142+
}).toErrorDev(
143+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
144+
);
148145
}
149146

150147
componentDidUpdate() {
151-
renderSubtreeIntoContainer(this, <Component />, portal);
148+
expect(() => {
149+
renderSubtreeIntoContainer(this, <Component />, portal);
150+
}).toErrorDev(
151+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
152+
);
152153
}
153154
}
154155

@@ -192,11 +193,19 @@ describe('renderSubtreeIntoContainer', () => {
192193
}
193194

194195
componentDidMount() {
195-
renderSubtreeIntoContainer(this, <Component />, portal);
196+
expect(() => {
197+
renderSubtreeIntoContainer(this, <Component />, portal);
198+
}).toErrorDev(
199+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
200+
);
196201
}
197202

198203
componentDidUpdate() {
199-
renderSubtreeIntoContainer(this, <Component />, portal);
204+
expect(() => {
205+
renderSubtreeIntoContainer(this, <Component />, portal);
206+
}).toErrorDev(
207+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
208+
);
200209
}
201210
}
202211

@@ -217,7 +226,11 @@ describe('renderSubtreeIntoContainer', () => {
217226
}
218227

219228
componentDidMount() {
220-
renderSubtreeIntoContainer(this, <div>hello</div>, portal);
229+
expect(() => {
230+
renderSubtreeIntoContainer(this, <div>hello</div>, portal);
231+
}).toErrorDev(
232+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
233+
);
221234
}
222235
}
223236

@@ -247,7 +260,11 @@ describe('renderSubtreeIntoContainer', () => {
247260
return null;
248261
}
249262
componentDidMount() {
250-
renderSubtreeIntoContainer(this, <Child />, portal);
263+
expect(() => {
264+
renderSubtreeIntoContainer(this, <Child />, portal);
265+
}).toErrorDev(
266+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
267+
);
251268
}
252269
}
253270

@@ -278,7 +295,11 @@ describe('renderSubtreeIntoContainer', () => {
278295
return {value: this.props.value};
279296
}
280297
componentDidMount() {
281-
renderSubtreeIntoContainer(this, <Middle />, portal1);
298+
expect(() => {
299+
renderSubtreeIntoContainer(this, <Middle />, portal1);
300+
}).toErrorDev(
301+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
302+
);
282303
}
283304
static childContextTypes = {
284305
value: PropTypes.string.isRequired,
@@ -290,7 +311,11 @@ describe('renderSubtreeIntoContainer', () => {
290311
return null;
291312
}
292313
componentDidMount() {
293-
renderSubtreeIntoContainer(this, <Child />, portal2);
314+
expect(() => {
315+
renderSubtreeIntoContainer(this, <Child />, portal2);
316+
}).toErrorDev(
317+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported',
318+
);
294319
}
295320
}
296321

packages/react-dom/src/client/ReactDOM.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import {
3939
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
4040
import {canUseDOM} from 'shared/ExecutionEnvironment';
4141
import ReactVersion from 'shared/ReactVersion';
42-
import {
43-
warnUnstableRenderSubtreeIntoContainer,
44-
enableNewReconciler,
45-
} from 'shared/ReactFeatureFlags';
42+
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
4643

4744
import {
4845
getInstanceFromNode,
@@ -73,8 +70,6 @@ setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority);
7370
setGetCurrentUpdatePriority(getCurrentUpdatePriority);
7471
setAttemptHydrationAtPriority(runWithPriority);
7572

76-
let didWarnAboutUnstableRenderSubtreeIntoContainer = false;
77-
7873
if (__DEV__) {
7974
if (
8075
typeof Map !== 'function' ||
@@ -121,19 +116,6 @@ function renderSubtreeIntoContainer(
121116
containerNode: Container,
122117
callback: ?Function,
123118
) {
124-
if (__DEV__) {
125-
if (
126-
warnUnstableRenderSubtreeIntoContainer &&
127-
!didWarnAboutUnstableRenderSubtreeIntoContainer
128-
) {
129-
didWarnAboutUnstableRenderSubtreeIntoContainer = true;
130-
console.warn(
131-
'ReactDOM.unstable_renderSubtreeIntoContainer() is deprecated ' +
132-
'and will be removed in a future major release. Consider using ' +
133-
'React Portals instead.',
134-
);
135-
}
136-
}
137119
return unstable_renderSubtreeIntoContainer(
138120
parentComponent,
139121
element,

packages/react-dom/src/client/ReactDOMLegacy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ export function unstable_renderSubtreeIntoContainer(
316316
containerNode: Container,
317317
callback: ?Function,
318318
) {
319+
if (__DEV__) {
320+
console.error(
321+
'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported ' +
322+
'in React 18. Consider using a portal instead. Until you switch to ' +
323+
"the createRoot API, your app will behave as if it's running React " +
324+
'17. Learn more: https://reactjs.org/link/switch-to-createroot',
325+
);
326+
}
327+
319328
if (!isValidContainerLegacy(containerNode)) {
320329
throw new Error('Target container is not a DOM element.');
321330
}

packages/shared/ReactFeatureFlags.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const warnAboutDeprecatedLifecycles = true;
1919
export const enableLazyElements = true;
2020
export const enableComponentStackLocations = true;
2121
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
22-
export const warnUnstableRenderSubtreeIntoContainer = false;
2322
export const enablePersistentOffscreenHostContainer = false;
2423

2524
// -----------------------------------------------------------------------------

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
4747
export const enableTrustedTypesIntegration = false;
4848
export const disableTextareaChildren = false;
4949
export const disableModulePatternComponents = false;
50-
export const warnUnstableRenderSubtreeIntoContainer = false;
5150
export const warnAboutSpreadingKeyToJSX = false;
5251
export const enableSuspenseAvoidThisFallback = false;
5352
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = false;
4040
export const disableModulePatternComponents = false;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableSuspenseAvoidThisFallback = false;
4443
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = false;
4040
export const disableModulePatternComponents = false;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableSuspenseAvoidThisFallback = false;
4443
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = false;
4040
export const disableModulePatternComponents = false;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableComponentStackLocations = false;
4443
export const enableLegacyFBSupport = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = false;
4040
export const disableModulePatternComponents = true;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableSuspenseAvoidThisFallback = true;
4443
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = false;
4040
export const disableModulePatternComponents = false;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableSuspenseAvoidThisFallback = false;
4443
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.testing.www.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
3838
export const enableTrustedTypesIntegration = false;
3939
export const disableTextareaChildren = __EXPERIMENTAL__;
4040
export const disableModulePatternComponents = true;
41-
export const warnUnstableRenderSubtreeIntoContainer = false;
4241
export const warnAboutSpreadingKeyToJSX = false;
4342
export const enableSuspenseAvoidThisFallback = true;
4443
export const enableSuspenseAvoidThisFallbackFizz = false;

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ export const enableComponentStackLocations = true;
8888

8989
export const disableTextareaChildren = __EXPERIMENTAL__;
9090

91-
export const warnUnstableRenderSubtreeIntoContainer = false;
92-
9391
// Enable forked reconciler. Piggy-backing on the "variant" global so that we
9492
// don't have to add another test dimension. The build system will compile this
9593
// to the correct value.

0 commit comments

Comments
 (0)