Browser History: Fix early reset closing chats on reload (#6808)
This commit is contained in:
parent
d101cdf0d3
commit
a06fabd4f3
@ -52,6 +52,7 @@ let isAlteringHistory = false;
|
|||||||
let deferredHistoryOperations: HistoryOperation[] = [];
|
let deferredHistoryOperations: HistoryOperation[] = [];
|
||||||
let deferredPopstateOperations: HistoryOperationState[] = [];
|
let deferredPopstateOperations: HistoryOperationState[] = [];
|
||||||
let isSafariGestureAnimation = false;
|
let isSafariGestureAnimation = false;
|
||||||
|
let isHistoryInitialized = false;
|
||||||
|
|
||||||
// Do not remove: used for history unit tests
|
// Do not remove: used for history unit tests
|
||||||
if (IS_TEST) {
|
if (IS_TEST) {
|
||||||
@ -127,7 +128,14 @@ function resetHistory() {
|
|||||||
window.history.replaceState({ index: 0, historyUniqueSessionId }, '', PATH_BASE);
|
window.history.replaceState({ index: 0, historyUniqueSessionId }, '', PATH_BASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetHistory();
|
function ensureHistoryInitialized() {
|
||||||
|
if (isHistoryInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isHistoryInitialized = true;
|
||||||
|
resetHistory();
|
||||||
|
}
|
||||||
|
|
||||||
function cleanupClosed(alreadyClosedCount = 1) {
|
function cleanupClosed(alreadyClosedCount = 1) {
|
||||||
let countClosed = alreadyClosedCount;
|
let countClosed = alreadyClosedCount;
|
||||||
@ -164,6 +172,10 @@ function cleanupTrashedState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('popstate', ({ state }: PopStateEvent) => {
|
window.addEventListener('popstate', ({ state }: PopStateEvent) => {
|
||||||
|
if (!isHistoryInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isAlteringHistory) {
|
if (isAlteringHistory) {
|
||||||
isAlteringHistory = false;
|
isAlteringHistory = false;
|
||||||
if (deferredPopstateOperations.length) {
|
if (deferredPopstateOperations.length) {
|
||||||
@ -241,6 +253,8 @@ export default function useHistoryBack({
|
|||||||
shouldResetUrlHash?: boolean;
|
shouldResetUrlHash?: boolean;
|
||||||
onBack: VoidFunction;
|
onBack: VoidFunction;
|
||||||
}) {
|
}) {
|
||||||
|
ensureHistoryInitialized();
|
||||||
|
|
||||||
const lastOnBack = useLastCallback(onBack);
|
const lastOnBack = useLastCallback(onBack);
|
||||||
|
|
||||||
// Active index of the record
|
// Active index of the record
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user