@@ -22,6 +22,7 @@ import reactHotLoader from '../reactHotLoader'
2222import logger from '../logger'
2323import configuration , { internalConfiguration } from '../configuration'
2424import { areSwappable } from './utils'
25+ import { resolveType } from './resolver'
2526
2627let renderStack = [ ]
2728
@@ -224,6 +225,7 @@ const hotReplacementRender = (instance, stack) => {
224225 const { children } = stack
225226
226227 flow . forEach ( ( child , index ) => {
228+ let childType = child . type
227229 const stackChild = children [ index ]
228230 const next = instance => {
229231 // copy over props as long new component may be hidden inside them
@@ -258,12 +260,13 @@ const hotReplacementRender = (instance, stack) => {
258260 return
259261 }
260262
261- if ( typeof child . type !== typeof stackChild . type ) {
263+ // comparing rendered type to fiber.ElementType
264+ if ( typeof childType !== typeof stackChild . elementType ) {
262265 // Portals could generate undefined !== null
263- if ( child . type && stackChild . type ) {
266+ if ( childType && stackChild . type ) {
264267 logger . warn (
265268 'React-hot-loader: got ' ,
266- child . type ,
269+ childType ,
267270 'instead of' ,
268271 stackChild . type ,
269272 )
@@ -277,6 +280,7 @@ const hotReplacementRender = (instance, stack) => {
277280 if ( stackChild . children && stackChild . children [ 0 ] ) {
278281 scheduleInstanceUpdate ( stackChild . children [ 0 ] . instance )
279282 }
283+ childType = childType . type || childType
280284 }
281285
282286 if ( isForwardType ( child ) ) {
@@ -285,24 +289,22 @@ const hotReplacementRender = (instance, stack) => {
285289 try {
286290 next ( {
287291 children : ( child . props ? child . props . children : child . children [ 0 ] ) (
288- stackContext ( ) . get ( getContextProvider ( child . type ) ) ||
289- child . type [ CONTEXT_CURRENT_VALUE ] ,
292+ stackContext ( ) . get ( getContextProvider ( childType ) ) ||
293+ childType [ CONTEXT_CURRENT_VALUE ] ,
290294 ) ,
291295 } )
292296 } catch ( e ) {
293297 // do nothing, yet
294298 }
295- } else if ( typeof child . type !== 'function' ) {
299+ } else if ( typeof childType !== 'function' ) {
296300 // React
297- let childName = child . type
298- ? getComponentDisplayName ( child . type )
299- : 'empty'
301+ let childName = childType ? getComponentDisplayName ( childType ) : 'empty'
300302 let extraContext = stackContext ( )
301303
302304 if ( isContextProvider ( child ) ) {
303305 extraContext = new Map ( extraContext )
304306 extraContext . set (
305- getContextProvider ( child . type ) ,
307+ getContextProvider ( childType ) ,
306308 {
307309 ...( child . nextProps || { } ) ,
308310 ...( child . props || { } ) ,
@@ -313,7 +315,7 @@ const hotReplacementRender = (instance, stack) => {
313315
314316 renderStack . push ( {
315317 name : childName ,
316- type : child . type ,
318+ type : childType ,
317319 props : stack . instance . props ,
318320 context : extraContext ,
319321 } )
@@ -330,11 +332,16 @@ const hotReplacementRender = (instance, stack) => {
330332 )
331333 renderStack . pop ( )
332334 } else {
333- if ( child . type === stackChild . type ) {
335+ if ( childType === stackChild . type ) {
334336 next ( stackChild . instance )
335337 } else {
336338 // unwrap proxy
337- const childType = getElementType ( child )
339+ let childType = getElementType ( child )
340+
341+ if ( isMemoType ( child ) ) {
342+ childType = childType . type || childType
343+ }
344+
338345 if ( ! stackChild . type [ PROXY_KEY ] ) {
339346 if ( ! reactHotLoader . IS_REACT_MERGE_ENABLED ) {
340347 if ( isTypeBlacklisted ( stackChild . type ) ) {
@@ -351,6 +358,11 @@ const hotReplacementRender = (instance, stack) => {
351358 isRegisteredComponent ( stackChild . type )
352359 ) {
353360 // one of elements are registered via babel plugin, and should not be handled by hot swap
361+ if ( resolveType ( childType ) === resolveType ( stackChild . type ) ) {
362+ next ( stackChild . instance )
363+ } else {
364+ // one component replace another. This is normal situation
365+ }
354366 } else if ( areSwappable ( childType , stackChild . type ) ) {
355367 // they are both registered, or have equal code/displayname/signature
356368
0 commit comments