From 65d2446804d1e03a1f9c0931af48c6d51f6bd2b1 Mon Sep 17 00:00:00 2001 From: byGalax Date: Sun, 17 May 2026 14:51:22 +0200 Subject: [PATCH] fix(chat-switch): remount ConversationPage per conversation id --- apps/desktop/src/App.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index 61f9e8c..4dea5d3 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -1,5 +1,5 @@ import { lazy, Suspense } from 'react'; -import { HashRouter, Navigate, Outlet, Route, Routes } from 'react-router-dom'; +import { HashRouter, Navigate, Outlet, Route, Routes, useParams } from 'react-router-dom'; import { AppShell } from './components/AppShell'; import { CrashToast } from './components/CrashToast'; @@ -60,6 +60,18 @@ function RouteBoundary({ scope }: { scope: string }) { ); } +// Forces a fresh `ConversationPage` instance per `:id` so React unmounts +// the previous conversation entirely on switch. Without this, the same +// component instance handles every conversation, which leaks state +// between chats (messages, scroll position, composer drafts) for one +// render frame and gives the "flicker" we're trying to remove. +// `useConversationMessages` re-hydrates from `messageMemoryCache` on the +// fresh mount so previously-visited chats still render instantly. +function ConversationRoute() { + const { id } = useParams<{ id: string }>(); + return ; +} + export function App() { return ( @@ -114,7 +126,7 @@ export function App() { path=":id" element={ - + } />