mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-11-15 17:21:38 +03:00
B: Fix potential memory leaks
This commit is contained in:
parent
ef9d8f31ec
commit
b6c94cfe73
|
|
@ -1,5 +1,7 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { urls, useConceptNavigation } from '@/app';
|
import { urls, useConceptNavigation } from '@/app';
|
||||||
import { useAuthSuspense } from '@/features/auth';
|
import { useAuthSuspense } from '@/features/auth';
|
||||||
|
|
||||||
|
|
@ -9,12 +11,14 @@ export function HomePage() {
|
||||||
const router = useConceptNavigation();
|
const router = useConceptNavigation();
|
||||||
const { isAnonymous } = useAuthSuspense();
|
const { isAnonymous } = useAuthSuspense();
|
||||||
|
|
||||||
if (isAnonymous) {
|
useEffect(() => {
|
||||||
// Note: Timeout is needed to let router initialize
|
// Note: Timeout is needed to let router initialize
|
||||||
setTimeout(() => router.replace({ path: urls.login }), PARAMETER.minimalTimeout);
|
const timeoutId = setTimeout(() => {
|
||||||
} else {
|
router.replace({ path: isAnonymous ? urls.login : urls.library });
|
||||||
setTimeout(() => router.replace({ path: urls.library }), PARAMETER.minimalTimeout);
|
}, PARAMETER.minimalTimeout);
|
||||||
}
|
|
||||||
|
return () => clearTimeout(timeoutId);
|
||||||
|
}, [router, isAnonymous]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,28 @@ export function useBrowserNavigation() {
|
||||||
const end = useAppTransitionStore(state => state.endNavigation);
|
const end = useAppTransitionStore(state => state.endNavigation);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const onPopState = () => {
|
const onPopState = () => {
|
||||||
start();
|
start();
|
||||||
|
|
||||||
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback to end the navigation in case route completes with cache
|
// Fallback to end the navigation in case route completes with cache
|
||||||
setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
end();
|
end();
|
||||||
}, DELAY_CACHE_CHECK); // or cancel after Suspense/loader finishes
|
timeoutId = null;
|
||||||
|
}, DELAY_CACHE_CHECK);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('popstate', onPopState);
|
window.addEventListener('popstate', onPopState);
|
||||||
return () => window.removeEventListener('popstate', onPopState);
|
return () => {
|
||||||
|
window.removeEventListener('popstate', onPopState);
|
||||||
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [start, end]);
|
}, [start, end]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user