@@ -47,35 +47,37 @@ export function bootstrapLoader(options: APIOptions) {
4747 const urlParameters = new URLSearchParams ( ) ;
4848
4949 const startLoading = ( ) => {
50- if ( ! apiLoadedPromise ) {
51- apiLoadedPromise = new Promise ( ( resolve , reject ) => {
52- urlParameters . set ( "libraries" , [ ...libraries ] + "" ) ;
53- for ( const [ name , value ] of Object . entries ( options ) ) {
54- urlParameters . set (
55- name . replace ( / [ A - Z ] / g, ( t ) => "_" + t [ 0 ] . toLowerCase ( ) ) ,
56- value as string
57- ) ;
58- }
59- urlParameters . set ( "callback" , `google.maps.__ib__` ) ;
60-
61- const scriptEl = document . createElement ( "script" ) ;
62- scriptEl . src = `https://maps.googleapis.com/maps/api/js?${ urlParameters . toString ( ) } ` ;
63-
64- scriptEl . onerror = ( ) => {
65- reject ( new APILoadingError ( ) ) ;
66- } ;
67-
68- const nonceScript =
69- document . querySelector < HTMLScriptElement > ( "script[nonce]" ) ;
70- scriptEl . nonce = nonceScript ?. nonce || "" ;
71-
72- // @ts -ignore
73- google . maps [ "__ib__" ] = resolve ;
74-
75- document . head . append ( scriptEl ) ;
76- } ) ;
50+ if ( apiLoadedPromise ) {
51+ return apiLoadedPromise ;
7752 }
7853
54+ apiLoadedPromise = new Promise ( ( resolve , reject ) => {
55+ urlParameters . set ( "libraries" , [ ...libraries ] + "" ) ;
56+ for ( const [ name , value ] of Object . entries ( options ) ) {
57+ urlParameters . set (
58+ name . replace ( / [ A - Z ] / g, ( t ) => "_" + t [ 0 ] . toLowerCase ( ) ) ,
59+ value as string
60+ ) ;
61+ }
62+ urlParameters . set ( "callback" , `google.maps.__ib__` ) ;
63+
64+ const scriptEl = document . createElement ( "script" ) ;
65+ scriptEl . src = `https://maps.googleapis.com/maps/api/js?${ urlParameters . toString ( ) } ` ;
66+
67+ scriptEl . onerror = ( ) => {
68+ reject ( new APILoadingError ( ) ) ;
69+ } ;
70+
71+ const nonceScript =
72+ document . querySelector < HTMLScriptElement > ( "script[nonce]" ) ;
73+ scriptEl . nonce = nonceScript ?. nonce || "" ;
74+
75+ // @ts -ignore
76+ google . maps [ "__ib__" ] = resolve ;
77+
78+ document . head . append ( scriptEl ) ;
79+ } ) ;
80+
7981 return apiLoadedPromise ;
8082 } ;
8183
0 commit comments