From 46c6f8fb9b3f085a53e23a63900fe10c132bed14 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 3 May 2023 20:21:15 +0400 Subject: [PATCH] Reset url hash when page is inactive (#3146) Co-authored-by: Alexander Zinchuk --- src/components/main/AppInactive.tsx | 8 ++++++++ src/hooks/useHistoryBack.ts | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/main/AppInactive.tsx b/src/components/main/AppInactive.tsx index 8ae585be7..c055417db 100644 --- a/src/components/main/AppInactive.tsx +++ b/src/components/main/AppInactive.tsx @@ -1,6 +1,8 @@ import type { FC } from '../../lib/teact/teact'; import React, { useCallback } from '../../lib/teact/teact'; +import useHistoryBack from '../../hooks/useHistoryBack'; + import Button from '../ui/Button'; import appInactivePath from '../../assets/app-inactive.png'; @@ -11,6 +13,12 @@ const AppInactive: FC = () => { window.location.reload(); }, []); + useHistoryBack({ + isActive: true, + onBack: handleReload, + shouldResetUrlHash: true, + }); + return (
diff --git a/src/hooks/useHistoryBack.ts b/src/hooks/useHistoryBack.ts index 4d0f79e38..833fba760 100644 --- a/src/hooks/useHistoryBack.ts +++ b/src/hooks/useHistoryBack.ts @@ -231,13 +231,14 @@ window.addEventListener('popstate', ({ state }: PopStateEvent) => { export default function useHistoryBack({ isActive, shouldBeReplaced, + shouldResetUrlHash, hash, onBack, }: { isActive?: boolean; shouldBeReplaced?: boolean; hash?: string; - title?: string; + shouldResetUrlHash?: boolean; onBack: VoidFunction; }) { // Active index of the record @@ -279,9 +280,10 @@ export default function useHistoryBack({ index: indexRef.current, historyUniqueSessionId, }, - hash: hash ? `#${hash}` : undefined, + // Space is a hack to make the browser completely remove the hash + hash: hash ? `#${hash}` : (shouldResetUrlHash ? ' ' : undefined), }); - }, [hash, onBack, shouldBeReplaced]); + }, [hash, onBack, shouldBeReplaced, shouldResetUrlHash]); const processBack = useCallback(() => { // Only process back on open records