Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Tests print that ReactDOM.render is no longer supported in React 18

ErrorWarning: 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.

Short answer

React 18 warns when anything calls ReactDOM.render and runs that tree in React 17 mode. In tests the caller is either an old React Testing Library (before 13), a render call with legacyRoot turned on, or your own test helper. Upgrade the library, remove legacyRoot, or switch your helper to createRoot.

  • Applies to React 18, React 19, @testing-library/react 13 to 16, Jest 29
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See which versions of React and React Testing Library are installed, and find every call to ReactDOM.render in the project.

    npm ls react react-dom @testing-library/react
    grep -rn "ReactDOM.render\|from 'react-dom'" src
  2. 2Match what you see, then jump to its fix

    1. 1The warning appears in every test that calls render() from the library, and no source file calls ReactDOM.render.@testing-library/react is older than version 13Fix
    2. 2The library is current, but the warning shows only in the tests that pass the legacyRoot option.render() is called with legacyRoot: trueFix
    3. 3grep finds ReactDOM.render in src/index or in a test utils file.Your own entry file or test helper still calls ReactDOM.renderFix

What does the error look like?

  • 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.
  • The current testing environment is not configured to support act(...)

Cause 1 of 3

@testing-library/react is older than version 13

1Check

Version 13 of React Testing Library added support for React 18 and dropped React 17 and earlier. Older versions render through the legacy API.

npm ls @testing-library/react

2Fix

Update the library and its peer dependency @testing-library/dom.

npm install --save-dev @testing-library/react@latest @testing-library/dom@latest

3Verify

Run the tests; the warning is gone.

npx jest

Confirmed by github.com

Did this fix it?

Cause 2 of 3

render() is called with legacyRoot: true

1Check

The release notes say version 13 uses createRoot by default and that render(ui, { legacyRoot: true }) opts out, with console warnings because the legacy root API is deprecated in React 18.

grep -rn "legacyRoot" src

2Fix

Remove the option so the default createRoot path is used.

// before
render(<App />, { legacyRoot: true });
// after
render(<App />);

3Verify

Run the affected tests.

npx jest path/to/test

Confirmed by github.com

Did this fix it?

Cause 3 of 3

Your own entry file or test helper still calls ReactDOM.render

1Check

React 18 deprecates ReactDOM.render: using it warns and runs the app in React 17 mode.

grep -rn "render(" src/index.js src/index.tsx src/test-utils* 2>/dev/null

2Fix

Create a root with createRoot from react-dom/client and call root.render. If a test then says the environment is not configured for act(...), set the flag in your test setup file.

import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('app'));
root.render(<App />);

// test setup file, only when you use createRoot yourself in tests
globalThis.IS_REACT_ACT_ENVIRONMENT = true;

3Verify

Run the tests and start the app; no React 18 warning remains.

npx jest

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Upgrade React and @testing-library/react together, and check the library's release notes for the minimum React version.
  • Keep all rendering in one test-utils file so a future API change touches one place.
  • Treat console warnings in tests as failures in CI so a legacy API call does not hide.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.