From a6d5590430ab712b4f5729832d9633ced304dcb1 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 11 Nov 2026 20:28:02 -0800 Subject: [PATCH] fix(render): a setBase whose style fails no longer unsettles the earlier call whose base is still drawn: settled follows the call that last changed the base, in the stub and the Cesium port --- docs/RENDERER-CONTRACT.md | 3 ++- src/render/cesium/globe.js | 8 ++++++-- src/render/stub/index.js | 5 ++++- src/render/stub/stub.test.mjs | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/RENDERER-CONTRACT.md b/docs/RENDERER-CONTRACT.md index 6f1729991..7789c2a8f 100644 --- a/docs/RENDERER-CONTRACT.md +++ b/docs/RENDERER-CONTRACT.md @@ -364,7 +364,8 @@ What it draws of the style specification: The Cesium port loads the style before the base changes (a style that fails leaves the base as it was; a later `setBase`, or disposal, aborts the load and the overtaken call changes nothing, resolving with `imagery: []` and -`settled: false`), draws it as Web Mercator imagery under the +`settled: false`; a later call whose style fails leaves the earlier call's +base drawn, and that call settles), draws it as Web Mercator imagery under the base's other imagery (`src/render/cesium/vectorBase.js`, 256 px tiles to level 20, transparent where the style paints no opaque background; a tile whose request is cancelled, its layer removed, is not painted), and credits each source's attribution as plain text. The stub diff --git a/src/render/cesium/globe.js b/src/render/cesium/globe.js index 3e49d9a9c..fd5152caa 100644 --- a/src/render/cesium/globe.js +++ b/src/render/cesium/globe.js @@ -136,6 +136,8 @@ export function createCesiumGlobe( let photorealGen = 0; let terrainGen = 0; let baseGen = 0; + /** The `setBase` call whose base is drawn now (a failed one changes none). */ + let drawnGen = 0; /** Aborts the style load of the `setBase` in flight, if any. */ let baseLoad = null; let baseCredit = null; @@ -273,6 +275,7 @@ export function createCesiumGlobe( } if (!current()) return superseded(); } + drawnGen = gen; for (const handle of imagery.list()) handle.remove(); baseCredit?.(); baseCredit = base.credit && credits ? credits.addStatic(base.credit) : null; @@ -296,8 +299,9 @@ export function createCesiumGlobe( return { photoreal: photorealStatus, imagery: layers, - // A base a later call replaced has not settled. - settled: current() && isSettled('base'), + // A base a later call replaced has not settled; one whose later call + // failed is still drawn. + settled: gen === drawnGen && !disposed && isSettled('base'), }; } diff --git a/src/render/stub/index.js b/src/render/stub/index.js index ee15f0896..87574073c 100644 --- a/src/render/stub/index.js +++ b/src/render/stub/index.js @@ -1555,6 +1555,8 @@ export function createStubRenderer(options = {}) { let terrainKey = 'null'; // The last `setBase` wins; its style load in flight, if any. let baseGen = 0; + /** The `setBase` call whose base is drawn now (a failed one changes none). */ + let drawnGen = 0; let baseLoad = null; const globe = { async setBase(base) { @@ -1589,6 +1591,7 @@ export function createStubRenderer(options = {}) { } if (!current()) return superseded(); } + drawnGen = gen; 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. @@ -1599,7 +1602,7 @@ export function createStubRenderer(options = {}) { return { photoreal: photorealStatus, imagery: layers, - settled: current(), + settled: gen === drawnGen && !destroyed, }; }, async setPhotoreal(spec) { diff --git a/src/render/stub/stub.test.mjs b/src/render/stub/stub.test.mjs index a9950e0a4..c2b5bc2e7 100644 --- a/src/render/stub/stub.test.mjs +++ b/src/render/stub/stub.test.mjs @@ -253,3 +253,25 @@ test('two setBase calls, neither awaited, leave the later one’s imagery alone' assert.equal((await first).settled, false, 'the overtaken one'); r.destroy(); }); + +test('a later setBase whose style fails leaves the earlier one the base, settled', async () => { + const original = globalThis.fetch; + globalThis.fetch = async () => ({ ok: false, status: 500 }); + try { + const r = createStubRenderer(); + const first = r.globe.setBase({ + photoreal: null, + imagery: [{ kind: 'xyz', url: 'https://a.invalid/{z}/{x}/{y}.png' }], + }); + const second = r.globe.setBase({ + vector: { styleUrl: 'https://s.invalid/x' }, + }); + await assert.rejects(second); + const status = await first; + assert.deepEqual(r.globe.imagery.list(), status.imagery); + assert.equal(status.settled, true, 'its base is the one drawn'); + r.destroy(); + } finally { + globalThis.fetch = original; + } +});