Skip to content

Commit ae000f3

Browse files
committed
Wrap in useEffect to run once
1 parent 8040345 commit ae000f3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎apps/site/components/Downloads/Release/VersionDropdown.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import WithNoScriptSelect from '@node-core/ui-components/Common/Select/NoScriptSelect';
44
import { useLocale, useTranslations } from 'next-intl';
5-
import { use } from 'react';
5+
import { use, useEffect } from 'react';
66

77
import { redirect, usePathname } from '#site/navigation.mjs';
88
import { STATUS_KIND_MAP } from '#site/next.constants.mjs';
@@ -41,10 +41,13 @@ const VersionDropdown: FC = () => {
4141
};
4242

4343
// Ensure the initial route is correct based on the release status.
44-
const redirectPath = getRedirectPath(release.status);
45-
if (redirectPath) {
46-
redirect({ href: redirectPath, locale });
47-
}
44+
useEffect(() => {
45+
const redirectPath = getRedirectPath(release.status);
46+
if (redirectPath) {
47+
redirect({ href: redirectPath, locale });
48+
}
49+
// eslint-disable-next-line @eslint-react/exhaustive-deps -- deps are correct on first render, and this should not run again.
50+
}, []);
4851

4952
// Handle setting the new version or navigating to the correct route based on status.
5053
const setVersionOrNavigate = (version: string) => {

0 commit comments

Comments
 (0)