Skip to content

Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client". #1258

@jeffdlange

Description

@jeffdlange

Steps to reproduce

  1. import ReactRailsUJS from 'react_ujs'; in your app
  2. Make a call to ReactRailsUJS.mountComponents(someElement);
  3. Visit a page that includes one or more React components rendered using react-rails (e.g. <%= react_component 'Foo' %>)
  4. The following warning will appear in the JS console:
Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client".

Trace:
image

With the breadcrumbs leading to the following culprit: https://github.com/reactjs/react-rails/blob/v2.7.0-rc.0/react_ujs/src/renderHelpers.js#L16

It appears that renderHelpers.js is importing the default ReactDOM from react-dom, but at the time that it accesses ReactDOM.createRoot the warning shows up.

Expected behavior

ReactRailsUJS should be able to render components without triggering any warnings

Actual behavior

Warning is triggered. This isn't a showstopper yet, but will be once React 19 is released, and creates a lot of noise in the JS console.

System configuration

  • Shakapacker or Sprockets version: we are using vite_ruby 3.2.15
  • React-Rails version: 2.6.1 and 2.7.0.rc.0
  • React_UJS version: 2.6.2 and 2.7.0.rc.0
  • Rails version: 6.1.7.2
  • Ruby version: 3.2.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions