GeezerVison is showing github.com — Warn if renderSubtreeIntoContainer is called (#23355) · react/react@a5b2215
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/renderSubtreeIntoContainer-test.js +47-22Lines changed: 47 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,8 +16,6 @@ const ReactTestUtils = require('react-dom/test-utils'); | 16 | 16 | const renderSubtreeIntoContainer = require('react-dom') | 17 | 17 | .unstable_renderSubtreeIntoContainer; | 18 | 18 |
| 19 | | -const ReactFeatureFlags = require('shared/ReactFeatureFlags'); | 20 | | - | 21 | 19 | describe('renderSubtreeIntoContainer', () => { | 22 | 20 | it('should pass context when rendering subtree elsewhere', () => { | 23 | 21 | const portal = document.createElement('div'); | @@ -48,18 +46,13 @@ describe('renderSubtreeIntoContainer', () => { | 48 | 46 | } | 49 | 47 |
| 50 | 48 | 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 | + ); | 63 | 56 | } | 64 | 57 | } | 65 | 58 |
| @@ -144,11 +137,19 @@ describe('renderSubtreeIntoContainer', () => { | 144 | 137 | } | 145 | 138 |
| 146 | 139 | componentDidMount() { | 147 | | - renderSubtreeIntoContainer(this, <Component />, portal); | | 140 | + expect(() => { | | 141 | + renderSubtreeIntoContainer(this, <Component />, portal); | | 142 | + }).toErrorDev( | | 143 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 144 | + ); | 148 | 145 | } | 149 | 146 |
| 150 | 147 | componentDidUpdate() { | 151 | | - renderSubtreeIntoContainer(this, <Component />, portal); | | 148 | + expect(() => { | | 149 | + renderSubtreeIntoContainer(this, <Component />, portal); | | 150 | + }).toErrorDev( | | 151 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 152 | + ); | 152 | 153 | } | 153 | 154 | } | 154 | 155 |
| @@ -192,11 +193,19 @@ describe('renderSubtreeIntoContainer', () => { | 192 | 193 | } | 193 | 194 |
| 194 | 195 | componentDidMount() { | 195 | | - renderSubtreeIntoContainer(this, <Component />, portal); | | 196 | + expect(() => { | | 197 | + renderSubtreeIntoContainer(this, <Component />, portal); | | 198 | + }).toErrorDev( | | 199 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 200 | + ); | 196 | 201 | } | 197 | 202 |
| 198 | 203 | componentDidUpdate() { | 199 | | - renderSubtreeIntoContainer(this, <Component />, portal); | | 204 | + expect(() => { | | 205 | + renderSubtreeIntoContainer(this, <Component />, portal); | | 206 | + }).toErrorDev( | | 207 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 208 | + ); | 200 | 209 | } | 201 | 210 | } | 202 | 211 |
| @@ -217,7 +226,11 @@ describe('renderSubtreeIntoContainer', () => { | 217 | 226 | } | 218 | 227 |
| 219 | 228 | 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 | + ); | 221 | 234 | } | 222 | 235 | } | 223 | 236 |
| @@ -247,7 +260,11 @@ describe('renderSubtreeIntoContainer', () => { | 247 | 260 | return null; | 248 | 261 | } | 249 | 262 | componentDidMount() { | 250 | | - renderSubtreeIntoContainer(this, <Child />, portal); | | 263 | + expect(() => { | | 264 | + renderSubtreeIntoContainer(this, <Child />, portal); | | 265 | + }).toErrorDev( | | 266 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 267 | + ); | 251 | 268 | } | 252 | 269 | } | 253 | 270 |
| @@ -278,7 +295,11 @@ describe('renderSubtreeIntoContainer', () => { | 278 | 295 | return {value: this.props.value}; | 279 | 296 | } | 280 | 297 | componentDidMount() { | 281 | | - renderSubtreeIntoContainer(this, <Middle />, portal1); | | 298 | + expect(() => { | | 299 | + renderSubtreeIntoContainer(this, <Middle />, portal1); | | 300 | + }).toErrorDev( | | 301 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 302 | + ); | 282 | 303 | } | 283 | 304 | static childContextTypes = { | 284 | 305 | value: PropTypes.string.isRequired, | @@ -290,7 +311,11 @@ describe('renderSubtreeIntoContainer', () => { | 290 | 311 | return null; | 291 | 312 | } | 292 | 313 | componentDidMount() { | 293 | | - renderSubtreeIntoContainer(this, <Child />, portal2); | | 314 | + expect(() => { | | 315 | + renderSubtreeIntoContainer(this, <Child />, portal2); | | 316 | + }).toErrorDev( | | 317 | + 'ReactDOM.unstable_renderSubtreeIntoContainer() is no longer supported', | | 318 | + ); | 294 | 319 | } | 295 | 320 | } | 296 | 321 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOM.js +1-19Lines changed: 1 addition & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,10 +39,7 @@ import { | 39 | 39 | import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal'; | 40 | 40 | import {canUseDOM} from 'shared/ExecutionEnvironment'; | 41 | 41 | import ReactVersion from 'shared/ReactVersion'; | 42 | | -import { | 43 | | - warnUnstableRenderSubtreeIntoContainer, | 44 | | - enableNewReconciler, | 45 | | -} from 'shared/ReactFeatureFlags'; | | 42 | +import {enableNewReconciler} from 'shared/ReactFeatureFlags'; | 46 | 43 |
| 47 | 44 | import { | 48 | 45 | getInstanceFromNode, | @@ -73,8 +70,6 @@ setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority); | 73 | 70 | setGetCurrentUpdatePriority(getCurrentUpdatePriority); | 74 | 71 | setAttemptHydrationAtPriority(runWithPriority); | 75 | 72 |
| 76 | | -let didWarnAboutUnstableRenderSubtreeIntoContainer = false; | 77 | | - | 78 | 73 | if (__DEV__) { | 79 | 74 | if ( | 80 | 75 | typeof Map !== 'function' || | @@ -121,19 +116,6 @@ function renderSubtreeIntoContainer( | 121 | 116 | containerNode: Container, | 122 | 117 | callback: ?Function, | 123 | 118 | ) { | 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 | | - } | 137 | 119 | return unstable_renderSubtreeIntoContainer( | 138 | 120 | parentComponent, | 139 | 121 | element, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMLegacy.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -316,6 +316,15 @@ export function unstable_renderSubtreeIntoContainer( | 316 | 316 | containerNode: Container, | 317 | 317 | callback: ?Function, | 318 | 318 | ) { | | 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 | + | 319 | 328 | if (!isValidContainerLegacy(containerNode)) { | 320 | 329 | throw new Error('Target container is not a DOM element.'); | 321 | 330 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/ReactFeatureFlags.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,6 @@ export const warnAboutDeprecatedLifecycles = true; | 19 | 19 | export const enableLazyElements = true; | 20 | 20 | export const enableComponentStackLocations = true; | 21 | 21 | export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 22 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 23 | 22 | export const enablePersistentOffscreenHostContainer = false; | 24 | 23 |
| 25 | 24 | // ----------------------------------------------------------------------------- | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-fb.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 47 | 47 | export const enableTrustedTypesIntegration = false; | 48 | 48 | export const disableTextareaChildren = false; | 49 | 49 | export const disableModulePatternComponents = false; | 50 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 51 | 50 | export const warnAboutSpreadingKeyToJSX = false; | 52 | 51 | export const enableSuspenseAvoidThisFallback = false; | 53 | 52 | export const enableSuspenseAvoidThisFallbackFizz = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-oss.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | 39 | export const disableTextareaChildren = false; | 40 | 40 | export const disableModulePatternComponents = false; | 41 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 42 | 41 | export const warnAboutSpreadingKeyToJSX = false; | 43 | 42 | export const enableSuspenseAvoidThisFallback = false; | 44 | 43 | export const enableSuspenseAvoidThisFallbackFizz = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.test-renderer.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | 39 | export const disableTextareaChildren = false; | 40 | 40 | export const disableModulePatternComponents = false; | 41 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 42 | 41 | export const warnAboutSpreadingKeyToJSX = false; | 43 | 42 | export const enableSuspenseAvoidThisFallback = false; | 44 | 43 | export const enableSuspenseAvoidThisFallbackFizz = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.test-renderer.native.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | 39 | export const disableTextareaChildren = false; | 40 | 40 | export const disableModulePatternComponents = false; | 41 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 42 | 41 | export const warnAboutSpreadingKeyToJSX = false; | 43 | 42 | export const enableComponentStackLocations = false; | 44 | 43 | export const enableLegacyFBSupport = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.test-renderer.www.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | 39 | export const disableTextareaChildren = false; | 40 | 40 | export const disableModulePatternComponents = true; | 41 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 42 | 41 | export const warnAboutSpreadingKeyToJSX = false; | 43 | 42 | export const enableSuspenseAvoidThisFallback = true; | 44 | 43 | export const enableSuspenseAvoidThisFallbackFizz = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.testing.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | 39 | export const disableTextareaChildren = false; | 40 | 40 | export const disableModulePatternComponents = false; | 41 | | -export const warnUnstableRenderSubtreeIntoContainer = false; | 42 | 41 | export const warnAboutSpreadingKeyToJSX = false; | 43 | 42 | export const enableSuspenseAvoidThisFallback = false; | 44 | 43 | export const enableSuspenseAvoidThisFallbackFizz = false; | |
|