mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
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:
parent
e063a177dc
commit
210a676ed9
1 changed files with 17 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue