fix(threads): persist selectedThreadId across reloads (#1168)

This commit is contained in:
Steven Enamakel
2026-05-03 23:18:14 -07:00
committed by GitHub
parent 2b31337bb1
commit 644c5c8bd3
2 changed files with 19 additions and 4 deletions
+11 -3
View File
@@ -245,9 +245,17 @@ const Conversations = ({ variant = 'page' }: ConversationsProps = {}) => {
return;
}
if (data.threads.length > 0) {
const mostRecent = data.threads[0];
dispatch(setSelectedThread(mostRecent.id));
void dispatch(loadThreadMessages(mostRecent.id));
// Prefer the thread the user was last viewing (persisted across
// reloads via redux-persist on the `thread` slice). Only fall
// through to "most recent" if that thread no longer exists
// server-side (deleted, purged, or different user).
const persistedId = threadStateForSelect.selectedThreadId;
const resumeId =
persistedId && data.threads.some(t => t.id === persistedId)
? persistedId
: data.threads[0].id;
dispatch(setSelectedThread(resumeId));
void dispatch(loadThreadMessages(resumeId));
} else {
void handleCreateNewThread();
}
+8 -1
View File
@@ -52,10 +52,17 @@ const notificationPersistConfig = {
};
const persistedNotificationReducer = persistReducer(notificationPersistConfig, notificationReducer);
// Persist only the user's last-viewed thread id so a reload resumes where
// they were instead of falling through to "create a new thread". The
// thread list and per-thread message caches are re-fetched from the core
// on boot, so we deliberately don't persist them.
const threadPersistConfig = { key: 'thread', storage, whitelist: ['selectedThreadId'] };
const persistedThreadReducer = persistReducer(threadPersistConfig, threadReducer);
export const store = configureStore({
reducer: {
socket: socketReducer,
thread: threadReducer,
thread: persistedThreadReducer,
chatRuntime: chatRuntimeReducer,
channelConnections: persistedChannelConnectionsReducer,
accounts: persistedAccountsReducer,