reactjs/react-rails

View on GitHub
react_ujs/src/reactDomClient.js

Summary

Maintainability
A
0 mins
Test Coverage
import ReactDOM from "react-dom"
import supportsRootApi from "./supportsRootApi"

let reactDomClient = ReactDOM

if (supportsRootApi) {
  // This will never throw an exception, but it's the way to tell Webpack the dependency is optional
  // https://github.com/webpack/webpack/issues/339#issuecomment-47739112
  // Unfortunately, it only converts the error to a warning.
  try {
    // eslint-disable-next-line global-require,import/no-unresolved
    reactDomClient = require('react-dom/client');
  } catch (e) {
    // We should never get here, but if we do, we'll just use the default ReactDOM
    // and live with the warning.
    reactDomClient = ReactDOM;
  }
}

export default reactDomClient