From db80c9f14181226d4bc89fa2c5931ad6b4b8b6eb Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 11 Nov 2026 20:01:20 -0800 Subject: [PATCH] Stub setBase: imagery is added before photoreal is awaited An unawaited setBase with photoreal and imagery, followed by another, added its imagery after the later call had set its own, leaving both. The imagery now goes in before anything is awaited, as the Cesium port adds it, and an overtaken call resolves settled: false. --- src/render/stub/index.js | 11 +++++++++-- src/render/stub/stub.test.mjs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/render/stub/index.js b/src/render/stub/index.js index a8853658d..ee15f0896 100644 --- a/src/render/stub/index.js +++ b/src/render/stub/index.js @@ -1590,10 +1590,17 @@ export function createStubRenderer(options = {}) { if (!current()) return superseded(); } for (const layer of imageryLayers.slice()) layer.remove(); + // The imagery is added before anything is awaited, so a later call, + // which removes it, always finds it. + const layers = (base.imagery ?? []).map((spec) => addImagery(spec)); if (base.photoreal !== undefined) await globe.setPhotoreal(base.photoreal); - const layers = (base.imagery ?? []).map((spec) => addImagery(spec)); - return { photoreal: photorealStatus, imagery: layers, settled: true }; + // A base a later call replaced has not settled. + return { + photoreal: photorealStatus, + imagery: layers, + settled: current(), + }; }, async setPhotoreal(spec) { log('globe', 'setPhotoreal', [spec]); diff --git a/src/render/stub/stub.test.mjs b/src/render/stub/stub.test.mjs index 5ca990359..40cde5111 100644 --- a/src/render/stub/stub.test.mjs +++ b/src/render/stub/stub.test.mjs @@ -238,3 +238,17 @@ test('a slow vector setBase a later setBase supersedes changes nothing, nor one globalThis.fetch = original; } }); + +test('two setBase calls, neither awaited, leave the later one’s imagery alone', async () => { + const r = createStubRenderer(); + const url = (name) => `https://${name}.invalid/{z}/{x}/{y}.png`; + const first = r.globe.setBase({ + photoreal: null, + imagery: [{ kind: 'xyz', url: url('a') }], + }); + const second = r.globe.setBase({ imagery: [{ kind: 'xyz', url: url('b') }] }); + const [, later] = await Promise.all([first, second]); + assert.deepEqual(r.globe.imagery.list(), later.imagery); + assert.equal((await first).settled, false, 'the overtaken one'); + r.destroy(); +});