File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -72,12 +72,19 @@ export const wrapper = input => WrappedComponent => {
72
72
}
73
73
74
74
initialize ( options ) {
75
+ // Avoid race condition: remove previous 'load' listener
76
+ if ( this . unregisterLoadHandler ) {
77
+ this . unregisterLoadHandler ( ) ;
78
+ this . unregisterLoadHandler = null ;
79
+ }
80
+
75
81
// Load cache factory
76
82
const createCache = options . createCache || defaultCreateCache ;
77
83
78
84
// Build script
79
85
this . scriptCache = createCache ( options ) ;
80
- this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
86
+ this . unregisterLoadHandler =
87
+ this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
81
88
82
89
// Store information about loading container
83
90
this . LoadingContainer =
Original file line number Diff line number Diff line change @@ -9,15 +9,27 @@ export const ScriptCache = (function(global) {
9
9
10
10
Cache . _onLoad = function ( key ) {
11
11
return ( cb ) => {
12
+ let registered = true ;
13
+
14
+ function unregister ( ) {
15
+ registered = false ;
16
+ }
17
+
12
18
let stored = scriptMap . get ( key ) ;
19
+
13
20
if ( stored ) {
14
21
stored . promise . then ( ( ) => {
15
- stored . error ? cb ( stored . error ) : cb ( null , stored )
22
+ if ( registered ) {
23
+ stored . error ? cb ( stored . error ) : cb ( null , stored )
24
+ }
25
+
16
26
return stored ;
17
27
} ) ;
18
28
} else {
19
29
// TODO:
20
30
}
31
+
32
+ return unregister ;
21
33
}
22
34
}
23
35
You can’t perform that action at this time.
0 commit comments