fix(eslint): resolve setState-in-effect errors in dashboard components (#1362)

- LanguageSwitcher: remove mounted state + useLayoutEffect pattern
  Portal renders directly based on open state (SSR-safe without client check)
- UsageStats: replace stats-null check with isInitialLoad ref to avoid
  setState in effect body (cascading render issue)
This commit is contained in:
OKWN
2026-05-23 09:24:35 +07:00
committed by GitHub
parent 7bc97eae7b
commit d29b19bc27
2 changed files with 11 additions and 7 deletions
+8 -3
View File
@@ -1,6 +1,6 @@
"use client";
import { useState, useEffect, useMemo, useCallback } from "react";
import { useState, useEffect, useMemo, useCallback, useRef } from "react";
import { useSearchParams, useRouter } from "next/navigation";
import { FREE_PROVIDERS, AI_PROVIDERS } from "@/shared/constants/providers";
@@ -203,6 +203,7 @@ export default function UsageStats({ period: periodProp, setPeriod: setPeriodPro
const [viewMode, setViewMode] = useState("costs");
const [providers, setProviders] = useState([]);
const [periodLocal, setPeriodLocal] = useState("today");
const isInitialLoad = useRef(true);
const period = periodProp ?? periodLocal;
const setPeriod = setPeriodProp ?? setPeriodLocal;
@@ -231,8 +232,12 @@ export default function UsageStats({ period: periodProp, setPeriod: setPeriodPro
// Fetch filtered stats via REST when period changes
useEffect(() => {
// First load: show full spinner; subsequent: show subtle fetching indicator
if (!stats) setLoading(true);
else setFetching(true);
if (isInitialLoad.current) {
isInitialLoad.current = false;
setLoading(true);
} else {
setFetching(true);
}
fetch(`/api/usage/stats?period=${period}`)
.then((r) => r.ok ? r.json() : null)