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