From 44093066ec5b07be99cfe0d26fa46bdc248a702e Mon Sep 17 00:00:00 2001 From: npeter83 Date: Mon, 29 Jun 2026 00:48:18 +0200 Subject: [PATCH] fix(messages): don't inherit a stale chat thread across account switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switching accounts does location.reload(), which preserves history.state — so the new account re-mounted the Messages module from the previous account's _sub sub-view, whose partnerId belongs to the OLD identity (often the new account's own id → an empty self-thread). Symptom: after switching to the recipient you land on a blank thread and the just-received message never shows (F5 keeps history.state); only going back to the list and reopening the real conversation works. Fix: (1) strip _sub/_ov from history.state before the switch reload so the new account starts at the module root; (2) guard Messages so a thread view with partnerId === meId falls back to the conversation list (can't message yourself). --- frontend/src/components/Messages.tsx | 4 +++- frontend/src/components/NavSidebar.tsx | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Messages.tsx b/frontend/src/components/Messages.tsx index 0e514be..1ebdc06 100644 --- a/frontend/src/components/Messages.tsx +++ b/frontend/src/components/Messages.tsx @@ -22,7 +22,9 @@ export default function Messages({ meId }: { meId: number }) { // the module (open() pushes an entry; back() = history.back()). const { view, open, back } = useHistorySubview("list"); - if (typeof view === "object") { + // Guard against a stale sub-view whose partnerId is the current user's own id (you can't + // message yourself). This can be inherited across an account switch — fall back to the list. + if (typeof view === "object" && view.partnerId !== meId) { return (