render: setBase's settled is stated for overlapping calls: whether, when the call resolves, its base is still the one drawn and has settled; an earlier call resolving while a later style loads, or after it fails, is settled, and one resolving after a later call changed the base is not

This commit is contained in:
Sameh Khamis committed 2026-11-11 20:51:40 -08:00
1 parent 74e4ebcf65
commit dbe026b109
5 files changed
+58 -7

No files matched your search

+3 -1
View File
@@ -1598,7 +1598,9 @@ export function createStubRenderer(options = {}) {
const layers = (base.imagery ?? []).map((spec) => addImagery(spec));
if (base.photoreal !== undefined)
await globe.setPhotoreal(base.photoreal);
// A base a later call replaced has not settled.
// Settled when its base is still the one drawn: a later call changes
// the base only once its style loads, and one whose style fails never
// does (see the contract's setBase).
return {
photoreal: photorealStatus,
imagery: layers,
+35
View File
@@ -275,3 +275,38 @@ test('a later setBase whose style fails leaves the earlier one the base, settled
globalThis.fetch = original;
}
});
test('a setBase that ends while a later one’s style still loads is settled; the later one then replaces it', async () => {
const held = [];
const original = globalThis.fetch;
globalThis.fetch = () =>
new Promise((resolve) => {
held.push(() =>
resolve({
ok: true,
status: 200,
json: async () => ({ version: 8, sources: {}, layers: [] }),
}),
);
});
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' },
});
const status = await first;
assert.equal(status.settled, true, 'its base is still the one drawn');
assert.deepEqual(r.globe.imagery.list(), status.imagery);
held[0]();
const later = await second;
assert.equal(later.settled, true);
assert.deepEqual(r.globe.imagery.list(), later.imagery);
r.destroy();
} finally {
globalThis.fetch = original;
}
});