From a576e915b4a5b3380b0e6eff5c62d5235f47bb2a Mon Sep 17 00:00:00 2001 From: Nico <47644445+nicotsx@users.noreply.github.com> Date: Sun, 15 Feb 2026 18:58:05 +0100 Subject: [PATCH] refactor(continue-page): simplify useEffect to avoid unnecessary dependencies (#641) * refactor(continue-page): simplify useEffect to avoid unnecessary dependencies * fix: use the href of the url object instead of the object iself as the dep in the callback --------- Co-authored-by: Stavros --- .gitignore | 3 ++ frontend/src/pages/continue-page.tsx | 68 ++++++++++++++-------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index f12126b..47fa146 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ __debug_* # infisical /.infisical.json + +# traefik data +/traefik diff --git a/frontend/src/pages/continue-page.tsx b/frontend/src/pages/continue-page.tsx index 691703e..7d023ff 100644 --- a/frontend/src/pages/continue-page.tsx +++ b/frontend/src/pages/continue-page.tsx @@ -32,34 +32,43 @@ export const ContinuePage = () => { cookieDomain, ); - const handleRedirect = useCallback(() => { + const urlHref = url?.href; + + const hasValidRedirect = valid && allowedProto; + const showUntrustedWarning = + hasValidRedirect && !trusted && !disableUiWarnings; + const showInsecureWarning = + hasValidRedirect && httpsDowngrade && !disableUiWarnings; + const shouldAutoRedirect = + isLoggedIn && + hasValidRedirect && + !showUntrustedWarning && + !showInsecureWarning; + + const redirectToTarget = useCallback(() => { + if (!urlHref || hasRedirected.current) { + return; + } + hasRedirected.current = true; + window.location.assign(urlHref); + }, [urlHref]); + + const handleRedirect = useCallback(() => { setIsLoading(true); - window.location.assign(url!); - }, [url]); + redirectToTarget(); + }, [redirectToTarget]); useEffect(() => { - if (!isLoggedIn) { - return; - } - - if (hasRedirected.current) { - return; - } - - if ( - (!valid || !allowedProto || !trusted || httpsDowngrade) && - !disableUiWarnings - ) { + if (!shouldAutoRedirect) { return; } const auto = setTimeout(() => { - handleRedirect(); + redirectToTarget(); }, 100); const reveal = setTimeout(() => { - setIsLoading(false); setShowRedirectButton(true); }, 5000); @@ -67,18 +76,7 @@ export const ContinuePage = () => { clearTimeout(auto); clearTimeout(reveal); }; - }, [ - isLoggedIn, - hasRedirected, - valid, - allowedProto, - trusted, - httpsDowngrade, - disableUiWarnings, - setIsLoading, - handleRedirect, - setShowRedirectButton, - ]); + }, [shouldAutoRedirect, redirectToTarget]); if (!isLoggedIn) { return ( @@ -89,11 +87,11 @@ export const ContinuePage = () => { ); } - if (!valid || !allowedProto) { + if (!hasValidRedirect) { return ; } - if (!trusted && !disableUiWarnings) { + if (showUntrustedWarning) { return ( @@ -114,7 +112,7 @@ export const ContinuePage = () => {