js-api-loader icon indicating copy to clipboard operation
js-api-loader copied to clipboard

Reset/Delete/Clear

Open jpoehnelt opened this issue 5 years ago • 8 comments

Future feature work could include the ability to reset or clear the singleton, script tag, and window.google. This likely overlaps with #5.

Looking for more feedback on uses cases and waiting for the singleton pattern get some more usage.

Note: This pattern may result in duplicate billing charge...

jpoehnelt avatar Nov 13 '20 22:11 jpoehnelt

@jpoehnelt Does this issue related to browser warning : Aborted attempt to load Google Maps JS with @googlemaps/js-api-loader.This may result in undesirable behavior as script parameters may not match.?

I am wondering if there is any cleanup function to avoid this warning.(I am currently using this library in my NextJS project and try to clean up when component unmounted).

I've found there is deleteScript() method in loader but it's not working when it's used as useEffect return cleanup.

Hope I am at the right window...

TERADA-DANTE avatar Mar 04 '21 02:03 TERADA-DANTE

Does this issue related to browser warning

I'll change that message to be more specific. The issue is that the loader was called twice which is ok, but the same key, libraries, etc must be used. This could be related to #5 for libraries.

jpoehnelt avatar Mar 04 '21 15:03 jpoehnelt

I would love to see this. I'm trying to validate a API key for use with the Maps Javascript API and there's no way to do it other than loading the script, try to create a map and wait for gm_authFailure.

So, if the API key is invalid and a new one inserted I have to reload the script and try the map again.

cristian-rossi avatar Jun 28 '21 16:06 cristian-rossi

Which aspect are you trying to validate with the API key?

  1. key exists and is valid
  2. key restriction is correct
  3. api enabled for key

related: https://cloud.google.com/sdk/gcloud/reference/alpha/services/api-keys/describe

jpoehnelt avatar Jun 28 '21 16:06 jpoehnelt

@jpoehnelt On the client side I'm trying to: make sure the key has access to the Javascript API ( https://developers.google.com/maps/documentation/javascript )

I already have something to check other libraries like the places API where I try to call the AutocompleteService and if it fails it probably means the key does not have access to the places API.

cristian-rossi avatar Jun 28 '21 17:06 cristian-rossi

Here workaround:

if (loader) {
  loader.reset()
  delete window.google
  Loader.instance = undefined
}

boomfly avatar Jun 04 '22 11:06 boomfly

Which aspect are you trying to validate with the API key?

  1. key exists and is valid
  2. key restriction is correct
  3. API enabled for key

related: https://cloud.google.com/sdk/gcloud/reference/alpha/services/api-keys/describe

@jpoehnelt Do we have any method to validate the API key in the criteria you mentioned here? Instead of calling map library, I want to validate because, sometimes the key will be a valid one but it doesn't have access to the library, right?!

Can you please help!!

mageshk98 avatar Sep 12 '22 17:09 mageshk98

@jpoehnelt I have a Single Page Application where a new google maps map is created on 3 different routes.

When i switch between these three routes, the memory allocation keeps stacking with 20mb per route switch, because it seems webgl.js doesnt do proper cleanup even if i clear and reset all references in my own src files.

I think a Reset/Delete/Clear feature could help me clean up this memory leak aswell. Preferably in away that doesnt double api calls.

If you want to test it, go to https://mapcanvas3d.com and move between routes in the navigation.

crunchwrap89 avatar Jan 02 '23 19:01 crunchwrap89