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 165165 } , {
166166 key : 'initialize' ,
167167 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+
168174 // Load cache factory
169175 var createCache = options . createCache || defaultCreateCache ;
170176
171177 // Build script
172178 this . scriptCache = createCache ( options ) ;
173- this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
179+ this . unregisterLoadHandler = this . scriptCache . google . onLoad ( this . onLoad . bind ( this ) ) ;
174180
175181 // Store information about loading container
176182 this . LoadingContainer = options . LoadingContainer || DefaultLoadingContainer ;
Original file line number Diff line number Diff line change 2525
2626 Cache . _onLoad = function ( key ) {
2727 return function ( cb ) {
28+ var registered = true ;
29+
30+ function unregister ( ) {
31+ registered = false ;
32+ }
33+
2834 var stored = scriptMap . get ( key ) ;
35+
2936 if ( stored ) {
3037 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+
3242 return stored ;
3343 } ) ;
3444 } else {
3545 // TODO:
3646 }
47+
48+ return unregister ;
3749 } ;
3850 } ;
3951
You can’t perform that action at this time.
0 commit comments