-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate ReactDOM.render and ReactDOM.hydrate #21652
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
let ReactDOM = require('react-dom'); | ||
|
||
describe('ReactDOMRoot', () => { | ||
let container; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
container = document.createElement('div'); | ||
ReactDOM = require('react-dom'); | ||
}); | ||
|
||
test('deprecation warning for ReactDOM.render', () => { | ||
spyOnDev(console, 'error'); | ||
|
||
ReactDOM.render('Hi', container); | ||
expect(container.textContent).toEqual('Hi'); | ||
if (__DEV__) { | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error.calls.argsFor(0)[0]).toContain( | ||
'ReactDOM.render is no longer supported', | ||
); | ||
} | ||
}); | ||
|
||
test('deprecation warning for ReactDOM.hydrate', () => { | ||
spyOnDev(console, 'error'); | ||
|
||
container.innerHTML = 'Hi'; | ||
ReactDOM.hydrate('Hi', container); | ||
expect(container.textContent).toEqual('Hi'); | ||
if (__DEV__) { | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error.calls.argsFor(0)[0]).toContain( | ||
'ReactDOM.hydrate is no longer supported', | ||
); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,15 @@ export function hydrate( | |
container: Container, | ||
callback: ?Function, | ||
) { | ||
if (__DEV__) { | ||
console.error( | ||
'ReactDOM.hydrate is no longer supported in React 18. Use createRoot ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it weird that we say "no longer supported in React 18" as if it was ever supported in React 18? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'instead. Until you switch to the new API, your app will behave as ' + | ||
"if it's running React 17. Learn " + | ||
'more: https://reactjs.org/link/switch-to-createroot', | ||
); | ||
} | ||
|
||
invariant( | ||
isValidContainer(container), | ||
'Target container is not a DOM element.', | ||
|
@@ -250,6 +259,15 @@ export function render( | |
container: Container, | ||
callback: ?Function, | ||
) { | ||
if (__DEV__) { | ||
console.error( | ||
'ReactDOM.render is no longer supported in React 18. Use createRoot ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use "ReactDOM.render is deprecated in React 18" instead for consistent messaging? "not supported" sounds like it's no longer working. Unless the other deprecation warnings also use "not supported" instead of "deprecated". |
||
'instead. Until you switch to the new API, your app will behave as ' + | ||
"if it's running React 17. Learn " + | ||
'more: https://reactjs.org/link/switch-to-createroot', | ||
); | ||
} | ||
|
||
invariant( | ||
isValidContainer(container), | ||
'Target container is not a DOM element.', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gross but oh well