Stop the Today tab jumping the viewport too
The last change stopped showTab scrolling, which fixed four of the five tabs. Today kept jumping, because getting there is not an ordinary tab switch: it is a history step. Tapping the tab spends the armed entry with history.back(), the back button pops the same one, and either way the browser restores the scroll position it saved against the entry it lands on — wherever you happened to be when you left Today. showTab scrolling nothing made no difference; the scroll was the browser's, not ours. So scroll restoration is turned off for the document. Tabs are not pages and carry no scroll of their own to restore, so the automatic behaviour has nothing useful to offer here. It also governs reloads, which now open at the top, which is the right place for this app to start anyway. The harness gained an assertion for it, and it was checked by removing the line and watching it fail — a browser silently undoing what the code just did is exactly the sort of thing that slips past a test that was never seen to break.
This commit is contained in:
+10
@@ -4721,6 +4721,16 @@
|
||||
// from tapping the tab.
|
||||
let backArmed = false;
|
||||
|
||||
// Returning to Today is a history navigation — by the back button, or by
|
||||
// tapping the tab, which spends the same entry — and a browser restores the
|
||||
// scroll position it saved against the entry it lands on. That position is
|
||||
// wherever you happened to be when you left Today, so the viewport jumped on
|
||||
// arrival even though showTab itself scrolls nothing. Tabs are not pages and
|
||||
// carry no scroll of their own to restore, so the automatic behaviour has
|
||||
// nothing useful to offer here and is turned off. (It also governs reloads,
|
||||
// which now open at the top — the right place to start anyway.)
|
||||
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
||||
|
||||
function armBack() {
|
||||
if (backArmed) return;
|
||||
history.pushState({ puppyTab: true }, "");
|
||||
|
||||
Reference in New Issue
Block a user