1
1
import { getIdByType , getProxyByType , getSignature , isColdType , updateProxyById } from './proxies' ;
2
2
import { hotComparisonOpen } from '../global/generation' ;
3
3
import {
4
+ getElementType ,
4
5
isContextType ,
5
6
isForwardType ,
6
7
isLazyType ,
@@ -20,31 +21,36 @@ const getInnerComponentType = component => {
20
21
} ;
21
22
22
23
function 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 ) ;
25
27
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
+ }
43
37
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 ) {
46
43
return false ;
47
44
}
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 ;
48
54
}
49
55
50
56
return true ;
@@ -99,7 +105,12 @@ const areDeepSwappable = (oldType, newType) => {
99
105
const compareComponents = ( oldType , newType , setNewType , baseType ) => {
100
106
let defaultResult = oldType === newType ;
101
107
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
+ ) {
103
114
return defaultResult ;
104
115
}
105
116
0 commit comments