diff --git a/src/global/actions/api/initial.ts b/src/global/actions/api/initial.ts index 2f124e763..1127818d5 100644 --- a/src/global/actions/api/initial.ts +++ b/src/global/actions/api/initial.ts @@ -30,7 +30,7 @@ import { forceWebsync } from '../../../util/websync'; import { addUsers, clearGlobalForLockScreen, updatePasscodeSettings } from '../../reducers'; import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode'; import { serializeGlobal } from '../../cache'; -import { parseInitialLocationHash } from '../../../util/routing'; +import { parseInitialLocationHash, resetInitialLocationHash } from '../../../util/routing'; import type { ActionReturnType } from '../../types'; import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { buildCollectionByKey } from '../../../util/iteratees'; @@ -157,6 +157,7 @@ addActionHandler('signOut', async (global, actions, payload): Promise => { if ('leaveGroupCall' in actions) actions.leaveGroupCall({ tabId: getCurrentTabId() }); try { + resetInitialLocationHash(); await unsubscribe(); await callApi('destroy'); await forceWebsync(false); diff --git a/src/hooks/useHistoryBack.ts b/src/hooks/useHistoryBack.ts index e0d5f26a4..8fe4611e6 100644 --- a/src/hooks/useHistoryBack.ts +++ b/src/hooks/useHistoryBack.ts @@ -8,7 +8,6 @@ import { IS_IOS } from '../util/windowEnvironment'; import useSyncEffect from './useSyncEffect'; import useEffectOnce from './useEffectOnce'; -export const LOCATION_HASH = window.location.hash; const PATH_BASE = `${window.location.pathname}${window.location.search}`; // Carefully selected by swiping and observing visual changes // TODO: may be different on other devices such as iPad, maybe take dpi into account? diff --git a/src/util/routing.ts b/src/util/routing.ts index d0b2f9b38..b72166e10 100644 --- a/src/util/routing.ts +++ b/src/util/routing.ts @@ -1,12 +1,24 @@ import type { MessageListType } from '../global/types'; import { MAIN_THREAD_ID } from '../api/types'; -import { LOCATION_HASH } from '../hooks/useHistoryBack'; import { IS_MOCKED_CLIENT } from '../config'; let parsedInitialLocationHash: Record | undefined; let messageHash: string | undefined; let isAlreadyParsed = false; +let LOCATION_HASH: string | undefined = window.location.hash; + +export function getInitialLocationHash() { + return LOCATION_HASH; +} + +export function resetInitialLocationHash() { + LOCATION_HASH = undefined; + isAlreadyParsed = false; + messageHash = undefined; + parsedInitialLocationHash = undefined; +} + export const createLocationHash = (chatId: string, type: MessageListType, threadId: number): string => { const displayType = type === 'thread' ? undefined : type; const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType]; @@ -55,21 +67,22 @@ export function parseInitialLocationHash() { if (isAlreadyParsed) return undefined; - if (!LOCATION_HASH) return undefined; + const locationHash = getInitialLocationHash(); + if (!locationHash) return undefined; - let parsedHash = LOCATION_HASH ? LOCATION_HASH.replace(/^#/, '') : undefined; - if (parsedHash?.includes('?')) { + let parsedHash = locationHash.replace(/^#/, ''); + if (parsedHash.includes('?')) { [messageHash, parsedHash] = parsedHash.split('?'); if (!IS_MOCKED_CLIENT) { window.location.hash = messageHash; } - } else if (parsedHash?.includes('=')) { + } else if (parsedHash.includes('=')) { if (!IS_MOCKED_CLIENT) { window.location.hash = ''; } } - parsedInitialLocationHash = parsedHash?.includes('=') ? parsedHash?.split('&').reduce((acc, cur) => { + parsedInitialLocationHash = parsedHash.includes('=') ? parsedHash.split('&').reduce((acc, cur) => { const [key, value] = cur.split('='); acc[key] = value; return acc;