File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1+ import ReactDOM from "react-dom"
2+
3+ const reactMajorVersion = ReactDOM . version ?. split ( '.' ) [ 0 ] || 16
4+
5+ // TODO: once we require React 18, we can remove this and inline everything guarded by it.
6+ const supportsRootApi = reactMajorVersion >= 18
7+
8+ let reactDomClient = ReactDOM
9+
10+ if ( supportsRootApi ) {
11+ // This will never throw an exception, but it's the way to tell Webpack the dependency is optional
12+ // https://github.com/webpack/webpack/issues/339#issuecomment-47739112
13+ // Unfortunately, it only converts the error to a warning.
14+ try {
15+ // eslint-disable-next-line global-require,import/no-unresolved
16+ reactDomClient = require ( 'react-dom/client' ) ;
17+ } catch ( e ) {
18+ // We should never get here, but if we do, we'll just use the default ReactDOM
19+ // and live with the warning.
20+ reactDomClient = ReactDOM ;
21+ }
22+ }
23+
24+ export default reactDomClient
Original file line number Diff line number Diff line change 1- import ReactDOM from "react-dom "
1+ import ReactDOM from "./reactDomClient "
22
33export function supportsHydration ( ) {
44 return typeof ReactDOM . hydrate === "function" || typeof ReactDOM . hydrateRoot === "function"
You can’t perform that action at this time.
0 commit comments