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 <steveiliop56@gmail.com>
This commit is contained in:
Nico
2026-02-15 18:58:05 +01:00
committed by GitHub
parent bce9e69186
commit a576e915b4
2 changed files with 36 additions and 35 deletions

3
.gitignore vendored
View File

@@ -39,3 +39,6 @@ __debug_*
# infisical # infisical
/.infisical.json /.infisical.json
# traefik data
/traefik

View File

@@ -32,34 +32,43 @@ export const ContinuePage = () => {
cookieDomain, 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; hasRedirected.current = true;
window.location.assign(urlHref);
}, [urlHref]);
const handleRedirect = useCallback(() => {
setIsLoading(true); setIsLoading(true);
window.location.assign(url!); redirectToTarget();
}, [url]); }, [redirectToTarget]);
useEffect(() => { useEffect(() => {
if (!isLoggedIn) { if (!shouldAutoRedirect) {
return;
}
if (hasRedirected.current) {
return;
}
if (
(!valid || !allowedProto || !trusted || httpsDowngrade) &&
!disableUiWarnings
) {
return; return;
} }
const auto = setTimeout(() => { const auto = setTimeout(() => {
handleRedirect(); redirectToTarget();
}, 100); }, 100);
const reveal = setTimeout(() => { const reveal = setTimeout(() => {
setIsLoading(false);
setShowRedirectButton(true); setShowRedirectButton(true);
}, 5000); }, 5000);
@@ -67,18 +76,7 @@ export const ContinuePage = () => {
clearTimeout(auto); clearTimeout(auto);
clearTimeout(reveal); clearTimeout(reveal);
}; };
}, [ }, [shouldAutoRedirect, redirectToTarget]);
isLoggedIn,
hasRedirected,
valid,
allowedProto,
trusted,
httpsDowngrade,
disableUiWarnings,
setIsLoading,
handleRedirect,
setShowRedirectButton,
]);
if (!isLoggedIn) { if (!isLoggedIn) {
return ( return (
@@ -89,11 +87,11 @@ export const ContinuePage = () => {
); );
} }
if (!valid || !allowedProto) { if (!hasValidRedirect) {
return <Navigate to="/logout" replace />; return <Navigate to="/logout" replace />;
} }
if (!trusted && !disableUiWarnings) { if (showUntrustedWarning) {
return ( return (
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm"> <Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -114,7 +112,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch gap-2"> <CardFooter className="flex flex-col items-stretch gap-2">
<Button <Button
onClick={() => handleRedirect()} onClick={handleRedirect}
loading={isLoading} loading={isLoading}
variant="destructive" variant="destructive"
> >
@@ -132,7 +130,7 @@ export const ContinuePage = () => {
); );
} }
if (httpsDowngrade && !disableUiWarnings) { if (showInsecureWarning) {
return ( return (
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm"> <Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -151,7 +149,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch gap-2"> <CardFooter className="flex flex-col items-stretch gap-2">
<Button <Button
onClick={() => handleRedirect()} onClick={handleRedirect}
loading={isLoading} loading={isLoading}
variant="warning" variant="warning"
> >
@@ -179,7 +177,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
{showRedirectButton && ( {showRedirectButton && (
<CardFooter className="flex flex-col items-stretch"> <CardFooter className="flex flex-col items-stretch">
<Button onClick={() => handleRedirect()}> <Button onClick={handleRedirect}>
{t("continueRedirectManually")} {t("continueRedirectManually")}
</Button> </Button>
</CardFooter> </CardFooter>