React 18, released on March 29, 2022, changes how a web application groups updates when developers replace ReactDOM.render with createRoot. Installing the new packages is not enough: applications that keep ReactDOM.render receive a warning and continue in React 17 mode. The root conversion enables automatic batching outside React event handlers, making it a separate point to test during an upgrade. [S1][S2]

The client entry point now imports createRoot from react-dom/client, creates a root for the page container and calls root.render. The old render callback is gone. React’s upgrade guide says there is no one-to-one replacement; the right alternative depends on what the callback did. Code that waited for that callback needs more than a renamed function. Applications attaching React to server-rendered HTML use hydrateRoot instead. [S2]

Batching changes when a sequence of updates reaches the page. React previously grouped updates inside its own event handlers by default, but not those inside timeouts, promises or native event handlers. With createRoot in React 18, those other updates are batched too. The guide’s timeout example changes two pieces of state and renders once rather than twice. For migration testing, inspect code that reads the page’s Document Object Model, or DOM, between state updates in such a callback: the old intermediate page state may no longer be available. The guide offers flushSync to opt out of batching and shows the DOM updated after each flushSync call. Use that as a specific remedy where the intermediate update is needed, rather than undoing batching throughout the application. [S2]

Strict Mode introduces a separate source of apparent breakage, and its scope matters. In development, React 18 simulates unmounting and remounting a component when it first mounts, running effect cleanup and setup again while restoring the previous state. Effects that assume they are set up or destroyed only once can fail that check. This does not mean production users receive the same extra Strict Mode cycle: the release announcement says Strict Mode does not change production behavior. Teams should distinguish a development cleanup problem from the changed batching behavior rather than treat both as the same regression. [S1][S2]

Tests that move to createRoot may also trigger a warning that the environment is not configured to support act, the testing helper. The upgrade guide tells unit-test-like environments to set globalThis.IS_REACT_ACT_ENVIRONMENT to true before running tests; React can then warn about updates that were not wrapped in act. It permits false for end-to-end tests that simulate a full browser and do not need act. Those are different test environments, not competing fixes for the same warning. [S2]

Browser requirements can stop the upgrade earlier. React 18 drops support for Internet Explorer because its new features use browser capabilities, including microtasks, that the project says cannot be adequately polyfilled there. For an application that must continue supporting Internet Explorer, the React team recommends staying on React 17. [S2]

Source documents

  1. React v18.0https://raw.githubusercontent.com/reactjs/reactjs.org/41c3ca570f007fed216e83ea7d06be6f3fa9fbdc/content/blog/2022-03-29-react-v18.md
  2. How to Upgrade to React 18https://raw.githubusercontent.com/reactjs/reactjs.org/41c3ca570f007fed216e83ea7d06be6f3fa9fbdc/content/blog/2022-03-08-react-18-upgrade-guide.md