11import type * as React from 'react' ;
2- import {
2+ import * as ReactDOM from 'react-dom' ;
3+ import type { Root } from 'react-dom/client' ;
4+
5+ type CreateRoot = ( container : ContainerType ) => Root ;
6+
7+ type InternalReactDOM = typeof ReactDOM & {
8+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ?: {
9+ usingClientEntryPoint ?: boolean ;
10+ } ;
11+ createRoot ?: CreateRoot ;
12+ } ;
13+
14+ const {
315 version,
4- render as reactRender ,
16+ render : reactRender ,
517 unmountComponentAtNode,
6- } from 'react-dom' ;
7- import type { Root } from 'react-dom/client' ;
18+ } = ReactDOM as InternalReactDOM ;
819
9- let createRoot : ( container : ContainerType ) => Root ;
20+ let createRoot : CreateRoot ;
1021try {
1122 const mainVersion = Number ( ( version || '' ) . split ( '.' ) [ 0 ] ) ;
1223 if ( mainVersion >= 18 ) {
13- ( { createRoot } = require ( 'react-dom/client' ) ) ;
24+ ( { createRoot } = ReactDOM as InternalReactDOM ) ;
1425 }
1526} catch ( e ) {
1627 // Do nothing;
1728}
1829
30+ function toggleWarning ( skip : boolean ) {
31+ const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } =
32+ ReactDOM as InternalReactDOM ;
33+
34+ if (
35+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED &&
36+ typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object'
37+ ) {
38+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED . usingClientEntryPoint =
39+ skip ;
40+ }
41+ }
42+
1943const MARK = '__rc_react_root__' ;
2044
2145// ========================== Render ==========================
@@ -24,7 +48,10 @@ type ContainerType = (Element | DocumentFragment) & {
2448} ;
2549
2650function modernRender ( node : React . ReactElement , container : ContainerType ) {
51+ toggleWarning ( true ) ;
2752 const root = container [ MARK ] || createRoot ( container ) ;
53+ toggleWarning ( false ) ;
54+
2855 root . render ( node ) ;
2956
3057 container [ MARK ] = root ;
0 commit comments