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

+6 -2
View File
@@ -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'),
};
}
+4 -1
View File
@@ -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) {
+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');
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;
}
});