11import { getIdByType , getProxyByType , getSignature , isColdType , updateProxyById } from './proxies' ;
22import { hotComparisonOpen } from '../global/generation' ;
33import {
4+ getElementType ,
45 isContextType ,
56 isForwardType ,
67 isLazyType ,
@@ -20,31 +21,36 @@ const getInnerComponentType = component => {
2021} ;
2122
2223function haveEqualSignatures ( prevType , nextType ) {
23- const prevSignature = getSignature ( prevType ) ;
24- const nextSignature = getSignature ( nextType ) ;
24+ try {
25+ const prevSignature = getSignature ( prevType ) ;
26+ const nextSignature = getSignature ( nextType ) ;
2527
26- if ( prevSignature === undefined && nextSignature === undefined ) {
27- return true ;
28- }
29- if ( prevSignature === undefined || nextSignature === undefined ) {
30- return false ;
31- }
32- if ( prevSignature . key !== nextSignature . key ) {
33- return false ;
34- }
35-
36- // TODO: we might need to calculate previous signature earlier in practice,
37- // such as during the first time a component is resolved. We'll revisit this.
38- const prevCustomHooks = prevSignature . getCustomHooks ( ) ;
39- const nextCustomHooks = nextSignature . getCustomHooks ( ) ;
40- if ( prevCustomHooks . length !== nextCustomHooks . length ) {
41- return false ;
42- }
28+ if ( prevSignature === undefined && nextSignature === undefined ) {
29+ return true ;
30+ }
31+ if ( prevSignature === undefined || nextSignature === undefined ) {
32+ return false ;
33+ }
34+ if ( prevSignature . key !== nextSignature . key ) {
35+ return false ;
36+ }
4337
44- for ( let i = 0 ; i < nextCustomHooks . length ; i ++ ) {
45- if ( ! haveEqualSignatures ( prevCustomHooks [ i ] , nextCustomHooks [ i ] ) ) {
38+ // TODO: we might need to calculate previous signature earlier in practice,
39+ // such as during the first time a component is resolved. We'll revisit this.
40+ const prevCustomHooks = prevSignature . getCustomHooks ( ) ;
41+ const nextCustomHooks = nextSignature . getCustomHooks ( ) ;
42+ if ( prevCustomHooks . length !== nextCustomHooks . length ) {
4643 return false ;
4744 }
45+
46+ for ( let i = 0 ; i < nextCustomHooks . length ; i ++ ) {
47+ if ( ! haveEqualSignatures ( prevCustomHooks [ i ] , nextCustomHooks [ i ] ) ) {
48+ return false ;
49+ }
50+ }
51+ } catch ( e ) {
52+ logger . error ( 'React-Hot-Loader: error occurred while comparing hook signature' , e ) ;
53+ return false ;
4854 }
4955
5056 return true ;
@@ -99,7 +105,12 @@ const areDeepSwappable = (oldType, newType) => {
99105const compareComponents = ( oldType , newType , setNewType , baseType ) => {
100106 let defaultResult = oldType === newType ;
101107
102- if ( ( oldType && ! newType ) || ( ! oldType && newType ) || typeof oldType !== typeof newType ) {
108+ if (
109+ ( oldType && ! newType ) ||
110+ ( ! oldType && newType ) ||
111+ typeof oldType !== typeof newType ||
112+ getElementType ( oldType ) !== getElementType ( newType )
113+ ) {
103114 return defaultResult ;
104115 }
105116
0 commit comments