diff --git a/src/maps/controller.js b/src/maps/controller.js index d2dd9b7b2..af7c49838 100644 --- a/src/maps/controller.js +++ b/src/maps/controller.js @@ -263,9 +263,15 @@ export class MapSourceController { this._onError?.(this._lastError, recovery); } } - // A stack that stays after the failed switch (and a failed recovery) - // still falls back on its tile failures, heard for this switch. - if (!recovered && this._imageryLayer && this._activeResolution) { + // A stack that stays after a failed choice (and a failed recovery) + // still falls back on its tile failures, heard for this switch. A + // failed fallback is not tried again on the next failures. + if ( + !recovered && + !automatic && + this._imageryLayer && + this._activeResolution + ) { this._removeImageryErrorListener?.(); this._removeImageryErrorListener = null; this._watchProvider(this._activeResolution, gen); diff --git a/src/maps/globeEngine.test.mjs b/src/maps/globeEngine.test.mjs index 0dedb549d..a20e0324b 100644 --- a/src/maps/globeEngine.test.mjs +++ b/src/maps/globeEngine.test.mjs @@ -271,6 +271,14 @@ test('a stack kept after a failed switch and a failed recovery still falls back for (const listener of [...tileErrors]) listener({}); for (let i = 0; i < 20; i++) await new Promise((r) => setTimeout(r, 0)); assert.ok(osmTries > tries, 'its tile failures still try its fallback'); + // That fallback failed too: the next failures do not try it again. + const retried = osmTries; + for (let n = 0; n < 3; n++) { + for (const listener of [...tileErrors]) listener({}); + for (const listener of [...tileErrors]) listener({}); + for (let i = 0; i < 20; i++) await new Promise((r) => setTimeout(r, 0)); + } + assert.equal(osmTries, retried, 'no retry storm'); } finally { console.warn = warn; controller.destroy(); diff --git a/src/ui/creditsView.js b/src/ui/creditsView.js index 187a26671..c46398db0 100644 --- a/src/ui/creditsView.js +++ b/src/ui/creditsView.js @@ -60,6 +60,8 @@ export function mountCreditsView(viewer, { root = document.body } = {}) { const bar = doc.createElement('div'); bar.id = 'gev-credits'; bar.className = 'gev-credits'; + // Takes focus back from an emptied list when the line has no link. + bar.tabIndex = -1; const line = doc.createElement('span'); line.className = 'gev-credits-line'; const expand = doc.createElement('button'); @@ -105,6 +107,7 @@ export function mountCreditsView(viewer, { root = document.body } = {}) { }; const render = (all) => { + const focused = panel.contains(doc.activeElement); const shown = distinct(Array.isArray(all) ? all : []); const inline = shown.filter((credit) => credit.inline); const listed = shown.filter((credit) => !credit.inline); @@ -124,9 +127,11 @@ export function mountCreditsView(viewer, { root = document.body } = {}) { expand.hidden = listed.length === 0; if (expand.hidden && !panel.hidden) { // Focus in the list goes back to the line, not to the page. - const focused = panel.contains(doc.activeElement); setOpen(false); - if (focused) line.querySelector('a')?.focus(); + if (focused) (line.querySelector('a') ?? bar).focus(); + } else if (focused && !panel.contains(doc.activeElement)) { + // A link that focus was on was redrawn: focus stays in the list. + close.focus(); } }; diff --git a/src/ui/creditsView.test.mjs b/src/ui/creditsView.test.mjs index cd265dd74..649fae4e3 100644 --- a/src/ui/creditsView.test.mjs +++ b/src/ui/creditsView.test.mjs @@ -107,3 +107,28 @@ test('the credits line is placed wherever the renderer’s own display is', asyn } assert.deepEqual(missing, []); }); + +test('focus in the list stays in it as it redraws, and goes to the line as it empties', () => { + const { viewer, renderer } = scene(); + renderer.credits.addStatic({ text: 'Esri', inline: true }); + const remove = renderer.credits.addStatic({ + text: 'OSM', + href: 'https://www.openstreetmap.org/copyright', + }); + const off = mountCreditsView(viewer); + const panel = document.getElementById('gev-credits-panel'); + document.querySelector('.gev-credits-expand').click(); + panel.querySelector('li a').focus(); + const removeOther = renderer.credits.addStatic({ text: 'NOAA' }); + assert.equal(panel.hidden, false); + assert.ok(panel.contains(document.activeElement), 'still in the list'); + remove(); + removeOther(); + assert.equal(panel.hidden, true); + assert.equal( + document.activeElement, + document.getElementById('gev-credits'), + 'a line with no link takes it', + ); + off(); +});