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(); +});