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';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { urls, useConceptNavigation } from '@/app';
|
||||
import { useAuthSuspense } from '@/features/auth';
|
||||
|
||||
|
|
@ -9,12 +11,14 @@ export function HomePage() {
|
|||
const router = useConceptNavigation();
|
||||
const { isAnonymous } = useAuthSuspense();
|
||||
|
||||
if (isAnonymous) {
|
||||
useEffect(() => {
|
||||
// Note: Timeout is needed to let router initialize
|
||||
setTimeout(() => router.replace({ path: urls.login }), PARAMETER.minimalTimeout);
|
||||
} else {
|
||||
setTimeout(() => router.replace({ path: urls.library }), PARAMETER.minimalTimeout);
|
||||
}
|
||||
const timeoutId = setTimeout(() => {
|
||||
router.replace({ path: isAnonymous ? urls.login : urls.library });
|
||||
}, PARAMETER.minimalTimeout);
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [router, isAnonymous]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,28 @@ export function useBrowserNavigation() {
|
|||
const end = useAppTransitionStore(state => state.endNavigation);
|
||||
|
||||
useEffect(() => {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const onPopState = () => {
|
||||
start();
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
// Fallback to end the navigation in case route completes with cache
|
||||
setTimeout(() => {
|
||||
timeoutId = setTimeout(() => {
|
||||
end();
|
||||
}, DELAY_CACHE_CHECK); // or cancel after Suspense/loader finishes
|
||||
timeoutId = null;
|
||||
}, DELAY_CACHE_CHECK);
|
||||
};
|
||||
|
||||
window.addEventListener('popstate', onPopState);
|
||||
return () => window.removeEventListener('popstate', onPopState);
|
||||
return () => {
|
||||
window.removeEventListener('popstate', onPopState);
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
}, [start, end]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user