fix(nav): Back onto a removed page also rewrites the entry to the feed

The fallback rendered the feed but left the history entry and the address bar on the dead page, so
a Feed click was a no-op (the same-page guard), filter mirroring kept `?page=messages` and the nav
diagnostics logged a page that does not exist. The entry is now replaced with the feed's, keeping
every other URL key (test red without it).
This commit is contained in:
2026-10-05 00:50:35 +02:00
parent 58ad95263c
commit 5257d57196
2 changed files with 8 additions and 0 deletions
@@ -199,8 +199,12 @@ export function NavigationProvider({ children }: { children: ReactNode }) {
function onPop(e: PopStateEvent) {
// An entry can name a page this build no longer has (one pushed before a module was removed,
// reached by Back after a reload onto the new build); that lands on the feed, not on a crash.
// The entry is rewritten to say so: left alone, the address bar would keep naming the dead page
// and a click on Feed would be a no-op (setPage's same-page guard).
const sf: unknown = e.state?.sfPage;
const p: Page = typeof sf === "string" && isPage(sf) ? sf : "feed";
if (typeof sf === "string" && sf !== p)
window.history.replaceState({ ...e.state, sfPage: p }, "", urlWithParams({ page: null }));
setPageState(p);
setAccountRaw(PAGE_KEY, p);
// The YouTube-search sub-view and the channel page ride in history.state, so Back/Forward