1- /* eslint-disable global-require,@typescript-eslint/no-require-imports */
2- import * as ReactDOM from 'react-dom' ;
1+ /* eslint-disable global-require,@typescript-eslint/no-require-imports,react/no-deprecated */
2+ import { version , hydrate , render , unmountComponentAtNode as unmountComponentAtNodeLib } from 'react-dom' ;
33import type { ReactElement } from 'react' ;
44import type { RenderReturnType } from './types/index.ts' with { 'resolution-mode' : 'import' } ;
55
6- const reactMajorVersion = Number ( ReactDOM . version ?. split ( '.' ) [ 0 ] ) || 16 ;
6+ const reactMajorVersion = Number ( version ?. split ( '.' ) [ 0 ] ) || 16 ;
77
88// TODO: once we require React 18, we can remove this and inline everything guarded by it.
99export const supportsRootApi = reactMajorVersion >= 18 ;
1010
11- export const supportsHydrate = supportsRootApi || ' hydrate' in ReactDOM ;
11+ export const supportsHydrate = supportsRootApi || ! ! hydrate ;
1212
1313// TODO: once React dependency is updated to >= 18, we can remove this and just
1414// import ReactDOM from 'react-dom/client';
@@ -20,20 +20,18 @@ if (supportsRootApi) {
2020 try {
2121 reactDomClient = require ( 'react-dom/client' ) as typeof import ( 'react-dom/client' ) ;
2222 } catch ( _e ) {
23- // We should never get here, but if we do, we'll just use the default ReactDOM
24- // and live with the warning.
25- reactDomClient = ReactDOM as unknown as typeof import ( 'react-dom/client' ) ;
23+ // do nothing
2624 }
2725}
2826
2927type HydrateOrRenderType = ( domNode : Element , reactElement : ReactElement ) => RenderReturnType ;
3028
31- /* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion,react/no-deprecated --
29+ /* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion --
3230 * while we need to support React 16
3331 */
3432export const reactHydrate : HydrateOrRenderType = supportsRootApi
3533 ? reactDomClient ! . hydrateRoot
36- : ( domNode , reactElement ) => ReactDOM . hydrate ( reactElement , domNode ) ;
34+ : ( domNode , reactElement ) => hydrate ( reactElement , domNode ) ;
3735
3836export function reactRender ( domNode : Element , reactElement : ReactElement ) : RenderReturnType {
3937 if ( supportsRootApi ) {
@@ -42,11 +40,10 @@ export function reactRender(domNode: Element, reactElement: ReactElement): Rende
4240 return root ;
4341 }
4442
45- // eslint-disable-next-line react/no-render-return-value
46- return ReactDOM . render ( reactElement , domNode ) ;
43+ return render ( reactElement , domNode ) ;
4744}
4845
49- export const unmountComponentAtNode : typeof ReactDOM . unmountComponentAtNode = supportsRootApi
46+ export const unmountComponentAtNode : typeof unmountComponentAtNodeLib = supportsRootApi
5047 ? // not used if we use root API
5148 ( ) => false
52- : ReactDOM . unmountComponentAtNode ;
49+ : unmountComponentAtNodeLib ;
0 commit comments