diff --git a/client/src/components/AtlasGlobe/GlobeEngine.ts b/client/src/components/AtlasGlobe/GlobeEngine.ts index 20204f883..b40a550f4 100644 --- a/client/src/components/AtlasGlobe/GlobeEngine.ts +++ b/client/src/components/AtlasGlobe/GlobeEngine.ts @@ -93,6 +93,16 @@ const WORLD_LOD_ZOOM: Array<[string, number]> = [ ['l0', 0], ]; const MAX_EDGE: Record = { l0: 8, l1: 4, l2: 2, r0: 3, r1: 1.5 }; + +/** + * What one visit to the Atlas loaded and built, kept for the next one in this + * tab: the manifest and the built world meshes, by file name (the name carries + * the content hash). Coming back then puts the globe up at once, instead of + * reading and triangulating the world again behind a loading notice. A new + * page load starts empty, so a deploy's new geometry is read as before. + */ +let keptManifest: Promise | null = null; +const keptWorlds = new Map(); const FIRST_REGION_ID = 512; export class GlobeEngine { @@ -206,7 +216,14 @@ export class GlobeEngine { private async boot(): Promise { try { - this.manifest = (await this.fetchRetrying('manifest')) as AtlasMeshManifest; + keptManifest ??= this.fetchRetrying('manifest') as Promise; + try { + this.manifest = await keptManifest; + } catch (err) { + // A failed read is not kept: the next visit asks again. + keptManifest = null; + throw err; + } await this.loadWorld('l0'); this.revealStart = this.now(); this.opts.onReady?.(); @@ -220,8 +237,13 @@ export class GlobeEngine { if (!this.manifest || this.renderer.hasWorld(lod) || this.worldLoading.has(lod)) return; this.worldLoading.add(lod); try { - const topo = (await this.fetchRetrying(`world/${this.manifest.world[lod]}`)) as Topology; - const layer = await this.build(topo, 'countries', MAX_EDGE[lod], 0); + const file = this.manifest.world[lod]; + let layer = keptWorlds.get(file); + if (!layer) { + const topo = (await this.fetchRetrying(`world/${file}`)) as Topology; + layer = await this.build(topo, 'countries', MAX_EDGE[lod], 0); + keptWorlds.set(file, layer); + } if (!this.alive) return; this.renderer.setWorld(lod, layer); this.kick();