fix(street-level): IC8 follow-ups for Google Street View

- An open after a failed one is no longer failed by the old panorama's
  status: only status_changed can reject; position_changed only resolves.
- A nearest lookup aborted, timed out or refused while Google's script
  loads no longer sends its getPanorama request once the script arrives.
- A panorama-details lookup that never answers times out after 10 s,
  cools down and retries; an unmount releases lookups in flight, and
  their late answers are dropped.
- Every Maps loader on a page shares one script load and ready callback,
  and either can retry a failed script.
- OPEN STREET VIEW aimed at the sky opens nothing and says to aim at a
  street, instead of looking up the camera footprint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Said TurkseverandClaude Opus 5.5 committed 2026-10-12 13:52:39 +01:00
1 parent 76db4114ff
commit 10f1986e38
10 files changed
+279 -30

No files matched your search

@@ -7,6 +7,11 @@
const SCRIPT_ORIGIN = 'https://maps.googleapis.com';
const READY_CALLBACK = '__gevGoogleMapsReady';
/**
* The page's one script load, kept on the page: every loader on it (two
* application instances, say) waits on the same script and callback.
*/
const PAGE_LOAD = Symbol.for('gev.googleMapsLoad');
/**
* @param {{getApiKey: () => string|null|undefined, document?: Document, global?: object}} options
@@ -16,8 +21,6 @@ export function createMapsLoader({
document = globalThis.document,
global = globalThis,
}) {
/** The script load in flight or done; cleared when it fails, so a retry can. */
let loading = null;
let authFailed = false;
let authHandlerInstalled = false;
const authListeners = new Set();
@@ -41,14 +44,15 @@ export function createMapsLoader({
}
function load() {
if (loading) return loading;
const key = getApiKey?.();
if (!key)
return Promise.reject(new Error('GOOGLE_MAPS_API_KEY is not set'));
if (global.google?.maps?.importLibrary)
return (loading = Promise.resolve(global.google.maps));
installAuthHandler();
loading = new Promise((resolve, reject) => {
if (global[PAGE_LOAD]) return global[PAGE_LOAD];
if (global.google?.maps?.importLibrary)
return Promise.resolve(global.google.maps);
// Cleared when the script fails, so a retry (from any loader) can.
const loading = new Promise((resolve, reject) => {
global[READY_CALLBACK] = () => {
delete global[READY_CALLBACK];
resolve(global.google.maps);
@@ -62,13 +66,14 @@ export function createMapsLoader({
callback: READY_CALLBACK,
})}`;
script.onerror = () => {
loading = null;
if (global[PAGE_LOAD] === loading) delete global[PAGE_LOAD];
script.remove();
delete global[READY_CALLBACK];
reject(new Error('The Google Maps JavaScript API could not load'));
};
document.head.append(script);
});
global[PAGE_LOAD] = loading;
return loading;
}