From bc7bc61f1f8a1bc5df9fe00bf1bfc2cc0d8d62de Mon Sep 17 00:00:00 2001 From: Coracle-Bot Date: Wed, 23 Sep 2026 07:05:01 +0000 Subject: [PATCH] Keep a deleted room out of the space history when leaving its page --- AGENTS.md | 2 ++ src/app/routes.ts | 34 +++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 46e2ad37..5c3378a1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -201,6 +201,8 @@ return a `Command`, so `.then(publish)` is usually all you need. - Navigate with `navigate` from `app/modal.ts` rather than `goto` — an open modal owns a history entry, and a navigation that drops the modal gives that entry back before it pushes its own. A plain `` inside a modal goes the same way, through `ModalContainer`'s `beforeNavigate` +- `navigate` is async and gives those entries back before it goes anywhere, so the page store + notifies again at the page being left — state cleared before the call has to survive that - Pass `keepModal` to `navigate` to change the page under a modal and leave it open ## Development Workflow diff --git a/src/app/routes.ts b/src/app/routes.ts index 8dc7e833..13cebbe5 100644 --- a/src/app/routes.ts +++ b/src/app/routes.ts @@ -42,22 +42,34 @@ export const highlightedEvent = writable(undefined) // in a space. A store because it's read from markup, unlike lastChatUrl. export const lastSpaceUrl = writable(undefined) -export const setupHistory = () => - page.subscribe($page => { - if ($page.params.relay) { - const url = decodeRelay($page.params.relay) +// The page store notifies on a modal opening or closing as well as on a navigation, and a modal +// leaves the url where it is. Only a changed path is somewhere the user went, and recording an +// unchanged one puts back a `lastPageBySpaceUrl` entry `forgetSpacePage` has just dropped. +export const setupHistory = () => { + let lastPath: string | undefined - if ($page.url.pathname !== makeSpacePath(url)) { - lastPageBySpaceUrl.set(url, $page.url.pathname) + return page.subscribe($page => { + const path = $page.url.pathname + + if (path !== lastPath) { + lastPath = path + + if ($page.params.relay) { + const url = decodeRelay($page.params.relay) + + if (path !== makeSpacePath(url)) { + lastPageBySpaceUrl.set(url, path) + } + + lastSpaceUrl.set(url) } - lastSpaceUrl.set(url) - } - - if ($page.params.chat) { - lastChatUrl = $page.url.pathname + if ($page.params.chat) { + lastChatUrl = path + } } }) +} // Profiles