Keep history entries untouched by unfinished globe picks and restore each visited entry's layers

A picked engine now lives in the switch until it runs; only then is the
address written, so a pick superseded by Back or one that fails rewrites no
entry. An engine-changing history visit holds the outgoing share link, which
neither restores nor writes the visited entry, and the running engine takes
the address back once the switch settles, restoring any entry visited while
it was held or not yet listening. Handed-off layers keep running where the
incoming address agrees with the outgoing one and follow a visited entry
where it differs. A failed recovery keeps the error on the loading screen
with an engine picker for a retry, and a failing reveal of the new globe no
longer blocks the cover removal or later requests.
This commit is contained in:
German Khokhlov committed 2026-11-03 15:24:20 +04:00
1 parent 9cc34e324f
commit a066a2d1ca
10 files changed
+539 -113

No files matched your search

+52
View File
@@ -424,3 +424,55 @@ test('the layer coordinator replaces in-flight share layers with the navigated s
);
coordinator.destroy();
});
test('a manager held for an engine-changing visit neither stamps nor restores that entry', (t) => {
const tab = installTab(t, SHARE_A);
const timers = installManualTimers(t);
const manager = new ShareLinkManager(fakeViewer());
manager.completeInitialRestore(manager.parseInitialHash().restoreToken);
// The page's own popstate listener runs first (src/main.js): the visit
// asks for another engine, so it holds this manager.
let engineChanges = false;
window.addEventListener('popstate', () => {
if (engineChanges) manager.holdNavigation();
});
const navigated = [];
manager.watchNavigation((state) => navigated.push(state));
tab.navigate(SHARE_B);
navigated.length = 0;
manager.completeInitialRestore(manager._restoreToken);
// A camera move has armed a debounced write of the outgoing view.
manager._scheduleUpdate();
assert.equal(timers.size, 1);
engineChanges = true;
tab.back();
assert.equal(timers.size, 0);
manager._scheduleUpdate();
manager._updateHash();
manager.flush();
window.dispatchEvent(new Event('hashchange'));
assert.equal(timers.size, 0);
assert.equal(window.location.hash, `#${SHARE_A}`);
assert.equal(navigated.length, 0);
// Kept after all (the next visit returned to this engine): it restores
// the entry it was held on and writes again.
manager.resumeNavigation();
assert.equal(navigated.length, 1);
assert.equal(navigated[0].lat, 10);
manager.destroy();
});
test('resuming navigation restores an entry visited before the manager watched', (t) => {
installTab(t, SHARE_A);
const manager = new ShareLinkManager(fakeViewer());
manager.completeInitialRestore(manager.parseInitialHash().restoreToken);
const navigated = [];
manager.watchNavigation((state) => navigated.push(state));
manager.resumeNavigation();
assert.equal(navigated.length, 0, 'the same entry is not restored again');
window.location.hash = SHARE_B;
manager.resumeNavigation();
assert.equal(navigated.length, 1);
assert.equal(navigated[0].lat, 48.8584);
manager.destroy();
});