Fix navigation during render warning

Move navigation logic from render to useEffect to prevent React warning
about state updates during render. Use ref to track redirect state and
handle both cloud mode (window.location.assign) and standard mode
(router.replace) navigation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sajid Mehmood 2025-11-12 13:04:13 -05:00
parent e063a177dc
commit 210a676ed9

View file

@ -1,5 +1,6 @@
'use client';
import { Grid, Loading, Column, Row } from '@umami/react-zen';
import { useEffect, useRef } from 'react';
import Script from 'next/script';
import { UpdateNotice } from './UpdateNotice';
import { SideNav } from '@/app/(main)/SideNav';
@ -11,16 +12,27 @@ export function App({ children }) {
const config = useConfig();
const { pathname, router } = useNavigation();
// Avoid navigation during render; perform redirect after commit.
const redirectedRef = useRef(false);
useEffect(() => {
if (redirectedRef.current) return;
if (isLoading) return;
if (error) {
redirectedRef.current = true;
if (process.env.cloudMode) {
window.location.assign('/login');
} else {
router.replace('/login');
}
}
}, [isLoading, error, router]);
if (isLoading || !config) {
return <Loading placement="absolute" />;
}
if (error) {
if (process.env.cloudMode) {
window.location.href = '/login';
} else {
router.push('/login');
}
// Navigation handled in effect to prevent React warning in dev.
return null;
}