@@ -117,53 +117,61 @@ const reactHotLoader = {
117117 configuration . showReactDomPatchNotification = false ;
118118 // console.warn('react-🔥-loader activated.');
119119 }
120- /* eslint-enable */
121- if ( ! React . createElement . isPatchedByReactHotLoader ) {
122- const originalCreateElement = React . createElement ;
123- // Trick React into rendering a proxy so that
124- // its state is preserved when the class changes.
125- // This will update the proxy if it's for a known type.
126- React . createElement = ( type , ...args ) => originalCreateElement ( resolveType ( type ) , ...args ) ;
127- React . createElement . isPatchedByReactHotLoader = true ;
120+ if ( ReactDOM && ReactDOM . setHotTypeResolver ) {
121+ console . log ( 'Types 2' ) ;
122+ configuration . intergratedResolver = true ;
123+ ReactDOM . setHotTypeResolver ( resolveType ) ;
128124 }
129125
130- if ( ! React . cloneElement . isPatchedByReactHotLoader ) {
131- const originalCloneElement = React . cloneElement ;
132-
133- React . cloneElement = ( element , ...args ) => {
134- const newType = element . type && resolveType ( element . type ) ;
135- if ( newType && newType !== element . type ) {
136- return originalCloneElement (
137- {
138- ...element ,
139- type : newType ,
140- } ,
141- ...args ,
142- ) ;
143- }
144- return originalCloneElement ( element , ...args ) ;
145- } ;
126+ if ( ! configuration . intergratedResolver ) {
127+ /* eslint-enable */
128+ if ( ! React . createElement . isPatchedByReactHotLoader ) {
129+ const originalCreateElement = React . createElement ;
130+ // Trick React into rendering a proxy so that
131+ // its state is preserved when the class changes.
132+ // This will update the proxy if it's for a known type.
133+ React . createElement = ( type , ...args ) => originalCreateElement ( resolveType ( type ) , ...args ) ;
134+ React . createElement . isPatchedByReactHotLoader = true ;
135+ }
146136
147- React . cloneElement . isPatchedByReactHotLoader = true ;
148- }
137+ if ( ! React . cloneElement . isPatchedByReactHotLoader ) {
138+ const originalCloneElement = React . cloneElement ;
139+
140+ React . cloneElement = ( element , ...args ) => {
141+ const newType = element . type && resolveType ( element . type ) ;
142+ if ( newType && newType !== element . type ) {
143+ return originalCloneElement (
144+ {
145+ ...element ,
146+ type : newType ,
147+ } ,
148+ ...args ,
149+ ) ;
150+ }
151+ return originalCloneElement ( element , ...args ) ;
152+ } ;
149153
150- if ( ! React . createFactory . isPatchedByReactHotLoader ) {
151- // Patch React.createFactory to use patched createElement
152- // because the original implementation uses the internal,
153- // unpatched ReactElement.createElement
154- React . createFactory = type => {
155- const factory = React . createElement . bind ( null , type ) ;
156- factory . type = type ;
157- return factory ;
158- } ;
159- React . createFactory . isPatchedByReactHotLoader = true ;
160- }
154+ React . cloneElement . isPatchedByReactHotLoader = true ;
155+ }
156+
157+ if ( ! React . createFactory . isPatchedByReactHotLoader ) {
158+ // Patch React.createFactory to use patched createElement
159+ // because the original implementation uses the internal,
160+ // unpatched ReactElement.createElement
161+ React . createFactory = type => {
162+ const factory = React . createElement . bind ( null , type ) ;
163+ factory . type = type ;
164+ return factory ;
165+ } ;
166+ React . createFactory . isPatchedByReactHotLoader = true ;
167+ }
161168
162- if ( ! React . Children . only . isPatchedByReactHotLoader ) {
163- const originalChildrenOnly = React . Children . only ;
164- // Use the same trick as React.createElement
165- React . Children . only = children => originalChildrenOnly ( { ...children , type : resolveType ( children . type ) } ) ;
166- React . Children . only . isPatchedByReactHotLoader = true ;
169+ if ( ! React . Children . only . isPatchedByReactHotLoader ) {
170+ const originalChildrenOnly = React . Children . only ;
171+ // Use the same trick as React.createElement
172+ React . Children . only = children => originalChildrenOnly ( { ...children , type : resolveType ( children . type ) } ) ;
173+ React . Children . only . isPatchedByReactHotLoader = true ;
174+ }
167175 }
168176
169177 if ( React . useEffect && ! React . useState . isPatchedByReactHotLoader ) {
0 commit comments