fix(nav): an item Back finds in another list is brought into view

This commit is contained in:
2026-10-28 22:04:07 +01:00
parent d825aff30d
commit 22d873ed49
2 changed files with 23 additions and 3 deletions
+5 -2
View File
@@ -492,7 +492,8 @@ function restoreTarget(
* list N may be another list, and <body> is the honest outcome — unless the item's name is the
* page's alone (`restoreTarget`). Gives up when the time is up, and at
* once when focus is already somewhere (the reader moved on, a dialog took it). The item is focused
* where the scroll restore put it, never scrolled to. (A stand-in the focus keeper placed when the view
* where the scroll restore put it, never scrolled to — but one found in another list is brought into
* view. (A stand-in the focus keeper placed when the view
* it held was swapped away counts as untouched, like <body>.) Returns a cancel. */
export function restoreNavPosition(pos: NavPosition): () => void {
const deadline = Date.now() + RESTORE_MS;
@@ -512,7 +513,9 @@ export function restoreNavPosition(pos: NavPosition): () => void {
// nearest one: names repeat (a log console's `http.request GET /api/feed 200` lines, two
// downloads of one video), and the first of them is rarely the one left behind.
const el = restoreTarget(all, list, pos);
if (el) return focusItem(el, false);
// Where the scroll restore put it — unless it is found in another list than the one it was left
// in: the restored scroll is the old place's, and the item would hold the focus off screen.
if (el) return focusItem(el, !list?.el.contains(el));
if (Date.now() < deadline) timer = setTimeout(attempt, RESTORE_POLL_MS);
};
// Not inside the popstate dispatch that landed: a sub-view's own listener (`useHistorySubview`)