From af49d50967c2e5587cb06a9c633088b45fd78903 Mon Sep 17 00:00:00 2001 From: sickerine Date: Tue, 1 Dec 2026 19:00:23 +0000 Subject: [PATCH] fix(workspaces): signing in lands in the organisation used last again The sign-in page counted as a page of the person's own workspace, so the moment the session started it cleared the organisation the browser remembered, and the home page that follows opened as the person's own. A page that is in no workspace now says nothing about which was used last, and the pages for signing in are such pages. --- components/workspaces/item-home.tsx | 17 +++++++++-------- lib/workspaces/paths.test.ts | 2 ++ lib/workspaces/paths.ts | 7 ++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/workspaces/item-home.tsx b/components/workspaces/item-home.tsx index 33a175339..d0ad829c3 100644 --- a/components/workspaces/item-home.tsx +++ b/components/workspaces/item-home.tsx @@ -54,23 +54,24 @@ export function TabWorkspace({ first, children }: { first: string | null; childr } /** - * Says in the rail's cookie which workspace this tab is in, on every page it opens, an item opened by the address's - * query included: an address that names no workspace opens in the one used last (proxy.ts `lastWorkspaceStart`, - * `TabWorkspace`). Apart from the rail, which a phone mounts only while its sheet is open, and which redraws in a tab - * left open behind. + * Says in the rail's cookie which workspace this tab is in, on every page of one that it opens, an item opened by the + * address's query included: an address that names no workspace opens in the one used last (proxy.ts + * `lastWorkspaceStart`, `TabWorkspace`). A page that is in no workspace says nothing, so signing in leaves it as it + * was. Apart from the rail, which a phone mounts only while its sheet is open, and which redraws in a tab left open + * behind. */ export function LastWorkspace() { - const key = lookKey(useWorkspaceSlug()); const pathname = usePathname(); + const named = addressWorkspace(pathname); const query = useSearchParams().toString(); const { userId } = useAuth(); // The browser's cookies are the outside system: the proxy and the server read them on the next page load. useEffect(() => { - if (!userId) return; + if (!userId || named === undefined) return; const raw = lookCookieIn(document.cookie); - const next = writeCache(usedLast(readCache(raw, userId), key), userId, key, undefined, undefined); + const next = writeCache(usedLast(readCache(raw, userId), lookKey(named)), userId, lookKey(named), undefined, undefined); if (next && next !== raw) document.cookie = lookCookieOut(next); - }, [userId, key, pathname, query]); + }, [userId, named, pathname, query]); return null; } diff --git a/lib/workspaces/paths.test.ts b/lib/workspaces/paths.test.ts index a9b1cb510..f5e19983d 100644 --- a/lib/workspaces/paths.test.ts +++ b/lib/workspaces/paths.test.ts @@ -103,6 +103,8 @@ it("names the workspace of every address, and none for a page that is the same i expect(addressWorkspace("/shared")).toBeNull(); expect(addressWorkspace("/papers/W1/a-title")).toBeUndefined(); expect(addressWorkspace("/privacy")).toBeUndefined(); + // Signing in is no use of a person's own workspace: the one used last has to outlast it. + expect(addressWorkspace("/sign-in/factor-one")).toBeUndefined(); // Such a page stays in the organization its tab was in: from it, a switch to the person's own workspace goes to their home page. expect(switchTarget(undefined, "/papers/W1", "")).toBe("/"); expect(switchTarget("lab", "/papers/W1", "")).toBe("/o/lab"); diff --git a/lib/workspaces/paths.ts b/lib/workspaces/paths.ts index 7a108a315..2e384d66c 100644 --- a/lib/workspaces/paths.ts +++ b/lib/workspaces/paths.ts @@ -20,10 +20,11 @@ const within = (path: string, section: string) => path === section || path.start const ORGANIZATION_ONLY = "/settings/workspace"; /** - * Pages that are in no workspace, the same whichever one the person works in: a paper's page and the policy pages. - * A tab that opens one stays in the workspace it was in (`addressWorkspace`). + * Pages that are in no workspace, the same whichever one the person works in: a paper's page, the policy pages and + * the pages for signing in. A tab that opens one stays in the workspace it was in (`addressWorkspace`), and opening + * one is no use of a workspace: signing in must not make a person's own workspace the one they used last. */ -const NO_WORKSPACE = ["/papers", "/privacy", "/terms", "/cookie-policy", "/credits"]; +const NO_WORKSPACE = ["/papers", "/privacy", "/terms", "/cookie-policy", "/credits", "/sign-in", "/sign-up"]; /** * The workspace a page's address names: an organization's slug under /o/, null for a person's own, and