diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/features/messages.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 64e36c5..7c81d27 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -3931,15 +3931,27 @@ export function messagesFeature(ctx) { pageReturn.push({ key, y }); if (pageReturn.length > 20) pageReturn.shift(); } - if (typeof window !== 'undefined') window.addEventListener('popstate', () => { - const top = pageReturn[pageReturn.length - 1]; - if (!top || pageKey() === top.key) return; - pageReturn.pop(); - const y = top.y; - // twice: the page under it may paint its rows a frame late - requestAnimationFrame(() => { try { window.scrollTo(0, y); } catch {} - requestAnimationFrame(() => { try { if (Math.abs(window.scrollY - y) > 2) window.scrollTo(0, y); } catch {} }); }); - }); + // Only Back OUT OF a profile or thread puts the reader back. Any other + // pop — a full-screen picture closing, a sheet — leaves the page where it + // is. It used to restore the newest remembered place on every pop, and a + // place goes stale whenever its page is left some other way (the Feed + // button from a thread): a photo's × then jumped the feed to wherever an + // earlier thread had been opened from, or to its top. + let pageLeft = ''; // the page a pop is leaving, read before the app restores the entry under it + if (typeof window !== 'undefined') { + window.addEventListener('popstate', () => { pageLeft = pageKey(); }, true); // capture: before the app's own handler re-renders + window.addEventListener('popstate', () => { + const left = pageLeft; pageLeft = ''; + if (!left || pageKey() === left) return; + const i = pageReturn.map((e) => e.key).lastIndexOf(left); + if (i < 0) return; + const y = pageReturn[i].y; + pageReturn.length = i; // this entry, and anything stale above it + // twice: the page under it may paint its rows a frame late + requestAnimationFrame(() => { try { window.scrollTo(0, y); } catch {} + requestAnimationFrame(() => { try { if (Math.abs(window.scrollY - y) > 2) window.scrollTo(0, y); } catch {} }); }); + }); + } function openProfile(pk) { rememberPlace('p:' + pk); ui.profilePk = pk; |
