File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 165
165
} , {
166
166
key : 'initialize' ,
167
167
value : function initialize ( options ) {
168
+ // Avoid race condition: remove previous 'load' listener
169
+ if ( this . unregisterLoadHandler ) {
170
+ this . unregisterLoadHandler ( ) ;
171
+ this . unregisterLoadHandler = null ;
172
+ }
173
+
168
174
// Load cache factory
169
175
var createCache = options . createCache || defaultCreateCache ;
170
176
171
177
// Build script
172
178
this . scriptCache = createCache ( options ) ;
173
- this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
179
+ this . unregisterLoadHandler = this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
174
180
175
181
// Store information about loading container
176
182
this . LoadingContainer = options . LoadingContainer || DefaultLoadingContainer ;
Original file line number Diff line number Diff line change 25
25
26
26
Cache . _onLoad = function ( key ) {
27
27
return function ( cb ) {
28
+ var registered = true ;
29
+
30
+ function unregister ( ) {
31
+ registered = false ;
32
+ }
33
+
28
34
var stored = scriptMap . get ( key ) ;
35
+
29
36
if ( stored ) {
30
37
stored . promise . then ( function ( ) {
31
- stored . error ? cb ( stored . error ) : cb ( null , stored ) ;
38
+ if ( registered ) {
39
+ stored . error ? cb ( stored . error ) : cb ( null , stored ) ;
40
+ }
41
+
32
42
return stored ;
33
43
} ) ;
34
44
} else {
35
45
// TODO:
36
46
}
47
+
48
+ return unregister ;
37
49
} ;
38
50
} ;
39
51
You can’t perform that action at this time.
0 commit comments