Skip to content

Bug: Can't use createRoot with UMD without "react-dom/client" warning #24372

Closed
@kentcdodds

Description

@kentcdodds

React version: v18.0.0

Steps To Reproduce

Run this:

<!DOCTYPE html>
<html>
<body>
  <div id="root"></div>
  <script src="https://unpkg.com/react@18.0.0/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@18.0.0/umd/react-dom.development.js"></script>
  <script type="module">
    const rootElement = document.getElementById('root')
    const element = React.createElement('div', {
      className: 'container',
      children: 'Hello World',
    })
    ReactDOM.createRoot(rootElement).render(element)
  </script>
</body>
</html>

Link to code example: https://jsbin.com/hucetewebu/edit?html,js,console,output

The current behavior

Getting a console error:

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

However, there's no UMD version of react-dom/client so the error is not actionable.

I am able to work around this by adding this to the top of the script:

ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = true

But obviously that's not a great solution, especially for what I'm trying to do 😅

The expected behavior

Disable the warning for UMD or give some other way to use createRoot from the UMD.

Use case

I use the UMD as a way to ease people into React without introducing a bunch of tooling up-front. Getting an error in the console is not a great experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions