Skip to content
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

Warning: ReactDOM.render is no longer supported in React 18 when using ReactTestUtils.renderIntoDocument #25446

Closed
raaaahman opened this issue Oct 7, 2022 · 6 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@raaaahman
Copy link

React version: 18.2.0
ReactDOM version: 18.2.0

Steps To Reproduce

  1. Setup Jest
  2. Create a test file which calls to the ReactTestUtils.renderIntoDocumentmethod
  3. Run jest

Example code:

test('component should render', () => {
  const container = renderIntoDocument(<MyComponent/>)

  expect(findRenderedComponentWithType(container, MyComponent)).not.toBeNull()
})

The current behavior

When using ReactTestUtils.renderIntoDocumentin React 18, I have the following warning in the console, that make the test fail:

console.error
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot 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

It seems to come from this line in the source code:

const div = document.createElement('div');

The expected behavior

I expect the ReactTestUtils.renderIntoDocument method not to trigger a console.error and to return a DOM Node.

I know most of the people are probably using @testing-library/react these days, should we expect the React Test Utilities to be deprecated soon?

Thank you for reading.

@raaaahman raaaahman added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Oct 7, 2022
@gaearon
Copy link
Collaborator

gaearon commented Oct 7, 2022

Yeah, TestUtils are essentially on life support. We try not to break them but they're frozen in functionality. renderIntoDocument doesn't do anything useful — it's an alias for ReactDOM.render into a new div (despite the naming). So I suggest to use createRoot directly or use Testing Library.

@raaaahman
Copy link
Author

raaaahman commented Oct 7, 2022

Thank you for the quick reply.

@YLeventhal
Copy link

YLeventhal commented Feb 1, 2023

So I suggest to use createRoot directly

@gaearon but the legacy ReactDOM.render returns a reference to the root ReactComponent instance while the new api returns void from render ?

or use Testing Library

I wonder if this is what you meant .... i use the testing library to render the component and place a ref on it so i still have access to the component instance ?

nikolas added a commit to ccnmtl/juxtapose that referenced this issue Feb 23, 2023
nikolas added a commit to ccnmtl/juxtapose that referenced this issue Feb 23, 2023
ReactTestUtils.render is deprecated:
facebook/react#25446

Also, the Xhr tests were failing with some node-fetch errors - I think
it's fine to just remove these as they weren't actually asserting any
business logic.
nikolas added a commit to ccnmtl/juxtapose that referenced this issue Feb 23, 2023
ReactTestUtils.render is deprecated:
facebook/react#25446

Also, the Xhr tests were failing with some node-fetch errors - I think
it's fine to just remove these as they weren't actually asserting any
business logic.
nikolas added a commit to ccnmtl/juxtapose that referenced this issue Feb 23, 2023
ReactTestUtils.render is deprecated:
facebook/react#25446

Also, the Xhr tests were failing with some node-fetch errors - I think
it's fine to just remove these as they weren't actually asserting any
business logic.
@eryue0220
Copy link

Is there any progress on this issue?

Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

5 participants
@gaearon @eryue0220 @raaaahman @YLeventhal and others