targomo / targomo-js-extensions

Google Maps extension for targomo-js
MIT License
2 stars 1 forks source link

Checking if window.google is undefined before using it. #18

Open getTobiasNielsen opened 4 years ago

getTobiasNielsen commented 4 years ago

"ReferenceError: google is not defined" @ node_modules/@targomo/googlemaps/targomo-googlemaps.umd.min.js:554

Capture

I am currently using React, and I am asynchroniously loading all my third party scripts. However, the above function is self invoking, and that causes issues as I am loading that script with import tgm from "@targomo/googlemaps" in a component that is loaded only when the google api is loaded. (react-google-maps-loader)

I am fairly new to React, so I am open to the idea that it is up to me to make sure google maps is fully loaded. If I have to wait for google to be fully loaded, then I cannot also at the same time load the extension, which means the loading would potentially take longer.

Hope to hear from you guys soon, take care!

Update: I managed to lazy load the scripts, but it was quite the struggle to get it to load asynchronously. Have a nice day, I hope my current project will bring you a lot of requests! :)

Update 2: Further tests make me believe that loading asynchroniously isn't possible at the moment. So I am defaulting to load the google maps api and the targomo/core api then dynamically loading the google extentions. Also found a CORB warning, see link below. corb

nunsinee commented 4 months ago

How you sove this issue ? , I am faceing with this now.

Screenshot 2024-04-26 at 14 05 55