1+ /* eslint-disable global-require,@typescript-eslint/no-require-imports */
12import * as ReactDOM from 'react-dom' ;
23import type { ReactElement } from 'react' ;
34import type { RenderReturnType } from './types/index.ts' with { 'resolution-mode' : 'import' } ;
@@ -15,7 +16,6 @@ if (supportsRootApi) {
1516 // https://github.com/webpack/webpack/issues/339#issuecomment-47739112
1617 // Unfortunately, it only converts the error to a warning.
1718 try {
18- // eslint-disable-next-line global-require,@typescript-eslint/no-require-imports
1919 reactDomClient = require ( 'react-dom/client' ) as typeof import ( 'react-dom/client' ) ;
2020 } catch ( _e ) {
2121 // We should never get here, but if we do, we'll just use the default ReactDOM
@@ -24,6 +24,21 @@ if (supportsRootApi) {
2424 }
2525}
2626
27+ export const ReactDOMServer = ( ( ) => {
28+ try {
29+ // in react-dom v18+
30+ return require ( 'react-dom/server' ) as typeof import ( 'react-dom/server' ) ;
31+ } catch ( _e ) {
32+ try {
33+ // in react-dom v16 or 17
34+ return require ( 'react-dom/server.js' ) as typeof import ( 'react-dom/server' ) ;
35+ } catch ( _e2 ) {
36+ // this should never happen, one of the above requires should succeed
37+ return undefined as unknown as typeof import ( 'react-dom/server' ) ;
38+ }
39+ }
40+ } ) ( ) ;
41+
2742type HydrateOrRenderType = ( domNode : Element , reactElement : ReactElement ) => RenderReturnType ;
2843
2944/* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion --
0 commit comments