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

This commit is contained in:
Sameh Khamis committed 2026-11-11 20:28:02 -08:00
1 parent 2a1e2d9c0b
commit a6d5590430
4 files changed
+34 -4

No files matched your search

+2 -1
View File
@@ -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 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 leaves the base as it was; a later `setBase`, or disposal, aborts the load and
the overtaken call changes nothing, resolving with `imagery: []` 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 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 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 whose request is cancelled, its layer removed, is not painted), and credits each source's attribution as plain text. The stub
+6 -2
View File
@@ -136,6 +136,8 @@ export function createCesiumGlobe(
let photorealGen = 0; let photorealGen = 0;
let terrainGen = 0; let terrainGen = 0;
let baseGen = 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. */ /** Aborts the style load of the `setBase` in flight, if any. */
let baseLoad = null; let baseLoad = null;
let baseCredit = null; let baseCredit = null;
@@ -273,6 +275,7 @@ export function createCesiumGlobe(
} }
if (!current()) return superseded(); if (!current()) return superseded();
} }
drawnGen = gen;
for (const handle of imagery.list()) handle.remove(); for (const handle of imagery.list()) handle.remove();
baseCredit?.(); baseCredit?.();
baseCredit = base.credit && credits ? credits.addStatic(base.credit) : null; baseCredit = base.credit && credits ? credits.addStatic(base.credit) : null;
@@ -296,8 +299,9 @@ export function createCesiumGlobe(
return { return {
photoreal: photorealStatus, photoreal: photorealStatus,
imagery: layers, imagery: layers,
// A base a later call replaced has not settled. // A base a later call replaced has not settled; one whose later call
settled: current() && isSettled('base'), // failed is still drawn.
settled: gen === drawnGen && !disposed && isSettled('base'),
}; };
} }
+4 -1
View File
@@ -1555,6 +1555,8 @@ export function createStubRenderer(options = {}) {
let terrainKey = 'null'; let terrainKey = 'null';
// The last `setBase` wins; its style load in flight, if any. // The last `setBase` wins; its style load in flight, if any.
let baseGen = 0; let baseGen = 0;
/** The `setBase` call whose base is drawn now (a failed one changes none). */
let drawnGen = 0;
let baseLoad = null; let baseLoad = null;
const globe = { const globe = {
async setBase(base) { async setBase(base) {
@@ -1589,6 +1591,7 @@ export function createStubRenderer(options = {}) {
} }
if (!current()) return superseded(); if (!current()) return superseded();
} }
drawnGen = gen;
for (const layer of imageryLayers.slice()) layer.remove(); for (const layer of imageryLayers.slice()) layer.remove();
// The imagery is added before anything is awaited, so a later call, // The imagery is added before anything is awaited, so a later call,
// which removes it, always finds it. // which removes it, always finds it.
@@ -1599,7 +1602,7 @@ export function createStubRenderer(options = {}) {
return { return {
photoreal: photorealStatus, photoreal: photorealStatus,
imagery: layers, imagery: layers,
settled: current(), settled: gen === drawnGen && !destroyed,
}; };
}, },
async setPhotoreal(spec) { async setPhotoreal(spec) {
+22
View File
@@ -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'); assert.equal((await first).settled, false, 'the overtaken one');
r.destroy(); 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;
}
});