From 9c06ed62a408374bd274c854177cf10588d19152 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Mon, 16 Mar 2026 18:17:21 -0700 Subject: [PATCH] Fix reopen-last behavior with new settings hash --- frontend/src/hooks/useConversationRouter.ts | 2 +- frontend/src/test/appStartupHash.test.tsx | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useConversationRouter.ts b/frontend/src/hooks/useConversationRouter.ts index 22c1131..128d8cb 100644 --- a/frontend/src/hooks/useConversationRouter.ts +++ b/frontend/src/hooks/useConversationRouter.ts @@ -211,7 +211,7 @@ export function useConversationRouter({ if (hashSyncEnabledRef.current && !suspendHashSync) { updateUrlHash(activeConversation); } - if (getReopenLastConversationEnabled() && activeConversation.type !== 'search') { + if (activeConversation.type !== 'search') { saveLastViewedConversation(activeConversation); } } diff --git a/frontend/src/test/appStartupHash.test.tsx b/frontend/src/test/appStartupHash.test.tsx index bdc68d1..19bcf2e 100644 --- a/frontend/src/test/appStartupHash.test.tsx +++ b/frontend/src/test/appStartupHash.test.tsx @@ -256,6 +256,37 @@ describe('App startup hash resolution', () => { expect(window.location.hash).toBe(''); }); + it('tracks the current conversation in local storage even before reopen is enabled', async () => { + const chatChannel = { + key: '11111111111111111111111111111111', + name: 'Ops', + is_hashtag: false, + on_radio: false, + last_read_at: null, + }; + + window.location.hash = ''; + mocks.api.getChannels.mockResolvedValue([publicChannel, chatChannel]); + localStorage.setItem( + LAST_VIEWED_CONVERSATION_KEY, + JSON.stringify({ + type: 'channel', + id: chatChannel.key, + name: chatChannel.name, + }) + ); + + render(); + + await waitFor(() => { + for (const node of screen.getAllByTestId('active-conversation')) { + expect(node).toHaveTextContent(`channel:${publicChannel.key}:Public`); + } + }); + + expect(localStorage.getItem(LAST_VIEWED_CONVERSATION_KEY)).toContain(publicChannel.key); + }); + it('restores last viewed contact from legacy name token when hash is empty and reopen is enabled', async () => { const aliceContact = { public_key: 'b'.repeat(64),