Google Maps Script Breaking Dynamic Buttons?

Google Maps Script Breaking Dynamic Buttons?

kossmn
Shopify Partner
1 0 0

Hi all,

 

I'm a developer building a custom theme and I'm adding in a "map" section using google maps with a user provided API key. I'm getting an error related to "this.googlePaySDK.payments" line inside the "payment-sheet" asset from shopify itself. 

Screenshot 2024-04-12 at 8.29.29 PM.png

 It seems to break the dynamic add to cart buttons throughout the site. I thought it was related to me using the new google maps importLibrary but I get this error when I'm using the legacy script tag as well.

The code in question is located in theme.liquid:

    {% if settings.google_maps_api_key != blank %}
      <script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({ key: "{{ settings.google_maps_api_key }}" });</script>
    {% endif %}

 It is copied directly from Google documentation. Has anyone run into this before?

And before suggested: no, I do not want to use an iframe.

Replies 0 (0)