@@ -8,6 +8,8 @@ const reactMajorVersion = Number(ReactDOM.version?.split('.')[0]) || 16;
8
8
// TODO: once we require React 18, we can remove this and inline everything guarded by it.
9
9
export const supportsRootApi = reactMajorVersion >= 18 ;
10
10
11
+ export const supportsHydrate = supportsRootApi || 'hydrate' in ReactDOM ;
12
+
11
13
// TODO: once React dependency is updated to >= 18, we can remove this and just
12
14
// import ReactDOM from 'react-dom/client';
13
15
let reactDomClient : typeof import ( 'react-dom/client' ) ;
@@ -24,7 +26,7 @@ if (supportsRootApi) {
24
26
}
25
27
}
26
28
27
- export const ReactDOMServer = ( ( ) => {
29
+ export const ReactDOMServer = /* #__PURE */ ( ( ) => {
28
30
try {
29
31
// in react-dom v18+
30
32
return require ( 'react-dom/server' ) as typeof import ( 'react-dom/server' ) ;
@@ -41,15 +43,12 @@ export const ReactDOMServer = (() => {
41
43
42
44
type HydrateOrRenderType = ( domNode : Element , reactElement : ReactElement ) => RenderReturnType ;
43
45
44
- /* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion --
46
+ /* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion,react/no-deprecated --
45
47
* while we need to support React 16
46
48
*/
47
- const hydrateProp = 'hydrate' ;
48
- const renderProp = 'render' ;
49
-
50
49
export const reactHydrate : HydrateOrRenderType = supportsRootApi
51
50
? reactDomClient ! . hydrateRoot
52
- : ( domNode , reactElement ) => ReactDOM [ hydrateProp ] ( reactElement , domNode ) ;
51
+ : ( domNode , reactElement ) => ReactDOM . hydrate ( reactElement , domNode ) ;
53
52
54
53
export function reactRender ( domNode : Element , reactElement : ReactElement ) : RenderReturnType {
55
54
if ( supportsRootApi ) {
@@ -58,6 +57,11 @@ export function reactRender(domNode: Element, reactElement: ReactElement): Rende
58
57
return root ;
59
58
}
60
59
61
- return ReactDOM [ renderProp ] ( reactElement , domNode ) ;
60
+ // eslint-disable-next-line react/no-render-return-value
61
+ return ReactDOM . render ( reactElement , domNode ) ;
62
62
}
63
- /* eslint-enable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion */
63
+
64
+ export const unmountComponentAtNode : typeof import ( 'react-dom' ) . unmountComponentAtNode = supportsRootApi
65
+ ? // not used if we use root API
66
+ ( ) => false
67
+ : ReactDOM . unmountComponentAtNode ;
0 commit comments