Skip to content

Commit 61336d0

Browse files
committed
Fix the hydration error on the login page
The page was rendering prior to the useEffect finishing fetching environment data and throwing the hydration mismatched html on the client. Signed-off-by: Brent Salisbury <[email protected]>
1 parent 94ddd85 commit 61336d0

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)