refactor(chat-switch): drop redundant id-change reset effect

This commit is contained in:
byGalax
2026-05-17 14:54:31 +02:00
parent 65d2446804
commit b9a3dde1aa
+8 -22
View File
@@ -94,18 +94,18 @@ type VirtuosoRow =
// change on every parent render. // change on every parent render.
const EMPTY_REACTIONS: AggregatedReaction[] = []; const EMPTY_REACTIONS: AggregatedReaction[] = [];
// Per-conversation scroll memory. Module-scoped so it survives re-mounts // Per-conversation scroll memory. Module-scoped so it survives the
// of ConversationPage when the route param (`id`) changes — switching // per-id remount of ConversationPage (see `ConversationRoute` in
// chats unmounts/remounts the page in our router setup. Session-only // App.tsx). Session-only (lost on reload, like Discord). The
// (lost on reload, like Discord). The `stickToBottom` flag is preserved // `stickToBottom` flag is preserved alongside the topmost-visible row
// alongside the topmost-visible row index so a chat the user left at the // index so a chat the user left at the bottom keeps auto-following new
// bottom keeps auto-following new messages when they return; a chat // messages when they return; a chat scrolled up returns to roughly the
// scrolled up returns to roughly the same row the user was reading. // same row the user was reading.
// //
// We track the topmost-visible row index rather than a pixel `scrollTop` // We track the topmost-visible row index rather than a pixel `scrollTop`
// because `react-virtuoso` virtualizes the list — the underlying scroll // because `react-virtuoso` virtualizes the list — the underlying scroll
// element's pixel offset depends on dynamically-measured row heights and // element's pixel offset depends on dynamically-measured row heights and
// is not stable across re-mounts. Using a row index restores the user's // is not stable across remounts. Using a row index restores the user's
// reading position even if some rows above re-render at different heights. // reading position even if some rows above re-render at different heights.
const scrollPositions = new Map<string, { topmostIndex: number; stickToBottom: boolean }>(); const scrollPositions = new Map<string, { topmostIndex: number; stickToBottom: boolean }>();
@@ -304,20 +304,6 @@ export function ConversationPage() {
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const composerRef = useRef<HTMLTextAreaElement>(null); const composerRef = useRef<HTMLTextAreaElement>(null);
useEffect(() => {
setReplyTo(null);
setForwardTarget(null);
setSearchOpen(false);
setMediaDrawerOpen(false);
setPollDialogOpen(false);
setSearchQuery('');
setDisplayCount(150);
setFirstUnreadId(null);
setFirstUnreadJumpDismissed(false);
setNewMessagesWhileAway(0);
previousMessageIdsRef.current = new Set();
firstUnreadComputedRef.current = false;
}, [id]);
useEffect(() => { useEffect(() => {
if (firstUnreadComputedRef.current) return; if (firstUnreadComputedRef.current) return;