@@ -122,55 +122,62 @@ const reactHotLoader = {
122
122
123
123
reactHotLoader . IS_REACT_MERGE_ENABLED = true ;
124
124
configuration . showReactDomPatchNotification = false ;
125
- // console.warn('react-🔥-loader activated.');
126
- }
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 ;
125
+
126
+ if ( ReactDOM . setHotTypeResolver ) {
127
+ configuration . intergratedResolver = true ;
128
+ ReactDOM . setHotTypeResolver ( resolveType ) ;
129
+ }
135
130
}
136
131
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
- } ;
132
+ if ( ! configuration . intergratedResolver ) {
133
+ /* eslint-enable */
134
+ if ( ! React . createElement . isPatchedByReactHotLoader ) {
135
+ const originalCreateElement = React . createElement ;
136
+ // Trick React into rendering a proxy so that
137
+ // its state is preserved when the class changes.
138
+ // This will update the proxy if it's for a known type.
139
+ React . createElement = ( type , ...args ) => originalCreateElement ( resolveType ( type ) , ...args ) ;
140
+ React . createElement . isPatchedByReactHotLoader = true ;
141
+ }
153
142
154
- React . cloneElement . isPatchedByReactHotLoader = true ;
155
- }
143
+ if ( ! React . cloneElement . isPatchedByReactHotLoader ) {
144
+ const originalCloneElement = React . cloneElement ;
145
+
146
+ React . cloneElement = ( element , ...args ) => {
147
+ const newType = element . type && resolveType ( element . type ) ;
148
+ if ( newType && newType !== element . type ) {
149
+ return originalCloneElement (
150
+ {
151
+ ...element ,
152
+ type : newType ,
153
+ } ,
154
+ ...args ,
155
+ ) ;
156
+ }
157
+ return originalCloneElement ( element , ...args ) ;
158
+ } ;
156
159
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
- }
160
+ React . cloneElement . isPatchedByReactHotLoader = true ;
161
+ }
168
162
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 ;
163
+ if ( ! React . createFactory . isPatchedByReactHotLoader ) {
164
+ // Patch React.createFactory to use patched createElement
165
+ // because the original implementation uses the internal,
166
+ // unpatched ReactElement.createElement
167
+ React . createFactory = type => {
168
+ const factory = React . createElement . bind ( null , type ) ;
169
+ factory . type = type ;
170
+ return factory ;
171
+ } ;
172
+ React . createFactory . isPatchedByReactHotLoader = true ;
173
+ }
174
+
175
+ if ( ! React . Children . only . isPatchedByReactHotLoader ) {
176
+ const originalChildrenOnly = React . Children . only ;
177
+ // Use the same trick as React.createElement
178
+ React . Children . only = children => originalChildrenOnly ( { ...children , type : resolveType ( children . type ) } ) ;
179
+ React . Children . only . isPatchedByReactHotLoader = true ;
180
+ }
174
181
}
175
182
176
183
if ( React . useEffect && ! React . useState . isPatchedByReactHotLoader ) {
0 commit comments