Skip to content

Commit 7723df3

Browse files
authored
Merge pull request #496 from nerdalert/bug-fix-hydration-error
Fix the hydration error on the login page
2 parents fa2c1ed + 61336d0 commit 7723df3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/app/login/page.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DevModeLogin from './devmodelogin';
1010
const Login: React.FunctionComponent = () => {
1111
const [deploymentType, setDeploymentType] = useState<string | 'github'>();
1212
const [isDevModeEnabled, setIsDevModeEnabled] = useState<boolean>(false);
13+
const [isLoading, setIsLoading] = useState<boolean>(true);
1314

1415
useEffect(() => {
1516
const chooseLoginPage = async () => {
@@ -21,16 +22,22 @@ const Login: React.FunctionComponent = () => {
2122
} catch (error) {
2223
console.error('Error fetching environment config:', error);
2324
setDeploymentType('github');
25+
} finally {
26+
setIsLoading(false);
2427
}
2528
};
2629
chooseLoginPage();
2730
}, []);
2831

32+
// Don't render the page until the useEffect finishes fetching environment data
33+
if (isLoading || deploymentType === null) {
34+
return <div style={{ color: 'white', padding: '1rem' }}>Loading...</div>;
35+
}
36+
2937
if (isDevModeEnabled) {
3038
return <DevModeLogin />;
3139
}
3240
if (deploymentType === 'native') {
33-
// Render a loading indicator or null while determining the environment
3441
return <NativeLogin />;
3542
}
3643
return (

0 commit comments

Comments
 (0)