- 
  Notifications
 
You must be signed in to change notification settings  - Fork 71
 
feat: Adopt the inline bootstrap loader #797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but we should retain support for the old way of loading, since a) removing it would be a major breaking change that requires a non-trivial code rewrite for users b) the old way is still officially valid and supported.
I think a good option would be to define a separate InlineLoaderOptions type, and have Loader accept both that and LoaderOptions. Then fork the logic based on the options object that Loader is instantiated with.
There's, of course, other ways to go about this, but we should make this change in a non-breaking way, so dropping the old loader entirely isn't an option.
Ah I see, I had thought the libraries specified in LoaderOptions wouldn't be available until after importLibrary was called, because I wasn't aware of the libraries options prop of the inline loader that you are able to pass those through to.
One question since I haven't been able to test this manually yes - if a user is still using Loader.load(), is google.maps.Map available when the callback in invoked? I ask because when using the inline loader script outside this library, you need to specify libraries: ['maps'] in the script to have google.maps.Map available on load.
One question since I haven't been able to test this manually yes - if a user is still using
Loader.load(), isgoogle.maps.Mapavailable when the callback in invoked?
It should be...
I ask because when using the inline loader script outside this library, you need to specify
libraries: ['maps']in the script to havegoogle.maps.Mapavailable on load.
That's not how it's intended to function. Gave it a quick test: https://jsfiddle.net/q1xe8fs0/ - google.maps.Map is available as soon as any part of maps JS is loaded. Happy to investigate a sample that demonstrates otherwise.
Aside: are there plans to fix the e2e tests (#795) soon? Happy to wait for that if we want to increase confidence. So far my testing has just been the unit tests.
That's not how it's intended to function. Gave it a quick test: https://jsfiddle.net/q1xe8fs0/ - google.maps.Map is available as soon as any part of maps JS is loaded. Happy to investigate a sample that demonstrates otherwise.
If I remove await google.maps.importLibrary("core"); from that jsfiddle, then google.maps.Map is not available. AFAIK, this is the expected behavior from the inline API loader, but doesn't that then introduce a breaking change into this lib?
If I upgrade after this PR, I would have to explicitly add CoreLibrary or MapLibrary to the libraries prop in the bootstrap, then load one of those with importLibrary. This would be so the google.maps.Map is available by default at load time, which is the current behavior. (or it could be that CoreLibrary would be the right choice here? Maybe MapLibrary doesn't provide the same APIs on load as the old loader - I haven't done a comprehensive comparison between them.)
So existing code that looks like this:
const loader = new Loader({ apiKey: "myKey", libraries: ["places"] }); loader .load() .then((google) => { new google.maps.Map(document.getElementById("map"), mapOptions); });
would instead have to look like this:
const loader = new Loader({ apiKey: "myKey", libraries: ["places", "maps"] // or "core" }); loader .load() .then(async (google) => { await google.maps.importLibrary("maps"); // or core new google.maps.Map(document.getElementById("map"), mapOptions); });
Aside: are there plans to fix the e2e tests (#795) soon? Happy to wait for that if we want to increase confidence. So far my testing has just been the unit tests.
I'll try to take a look soon, since I'd like to get this PR merged. Since this is going to change the lib to only use the inline loader script under the hood, can you also take a look at /examples and update whatever is needed there?
If I remove
await google.maps.importLibrary("core");from that jsfiddle, thengoogle.maps.Mapis not available. AFAIK, this is the expected behavior from the inline API loader, but doesn't that then introduce a breaking change into this lib?
That's because the inline bootstrap loader doesn't load anything until the first importLibrary call. That's why this PR includes a call to loader.importLibrary("core"); (really it could have been any library) inside setScript(), in order to maintain backwards compatibility.
If I upgrade after this PR, I would have to explicitly add
CoreLibraryorMapLibraryto thelibrariesprop in the bootstrap, then load one of those withimportLibrary. This would be so thegoogle.maps.Mapis available by default at load time, which is the current behavior. (or it could be thatCoreLibrarywould be the right choice here? MaybeMapLibrarydoesn't provide the same APIs on load as the old loader - I haven't done a comprehensive comparison between them.)So existing code that looks like this:
const loader = new Loader({ apiKey: "myKey", libraries: ["places"] }); loader .load() .then((google) => { new google.maps.Map(document.getElementById("map"), mapOptions); });...
Tested manually, this still works.
Since this is going to change the lib to only use the inline loader script under the hood, can you also take a look at
/examplesand update whatever is needed there?
done
ok awesome - I didn't catch the importLibrary call in setScript. I think we can go ahead and merge this then. It's going to take a while longer to figure out the e2e tests, but all they do is load the map and set center.
* Adopt the inline bootstrap loader: https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import and provide an importLibrary() alias 6fe1903
## [1.16.0](v1.15.2...v1.16.0) (2023年06月05日) ### Features * Adopt the inline bootstrap loader ([#797](#797)) ([6fe1903](6fe1903)) ### Miscellaneous Chores * Update jest.config.js ([559dc7e](559dc7e)) * Update release.yml ([f77bf1f](f77bf1f)) * Update release.yml ([c578e13](c578e13)) * Update release.yml ([0625600](0625600)) * Update release.yml ([2c02ac8](2c02ac8)) * Update release.yml ([6fae278](6fae278)) * Update release.yml ([e71b478](e71b478)) * Update release.yml ([18386f1](18386f1)) * Update release.yml ([105f3e9](105f3e9)) * Update release.yml ([b8019ac](b8019ac)) * Update release.yml ([3b9f3ac](3b9f3ac)) * Update release.yml ([cbcec6e](cbcec6e))
🎉 This PR is included in version 1.16.0 🎉
The release is available on:
- GitHub release
 npm package (@latest dist-tag)v1.16.0
Your semantic-release bot 📦🚀
https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import