Fix race condition in useEffect hooks and type assertion bug (#2827)

- Add active flag pattern to 3 useEffect hooks in App.tsx to prevent
  event listener leaks when component unmounts before async setup completes
- Add guard check in useSettings.ts to prevent undefined from being
  stored in localStorage when payload.language is missing

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Zylo
2026-05-18 09:36:44 +08:00
committed by GitHub
parent 4f0f103a8a
commit 8786f44c5a
2 changed files with 28 additions and 12 deletions
+2 -7
View File
@@ -14,8 +14,6 @@ import {
} from "./useDirectorySettings";
import { useSettingsMetadata } from "./useSettingsMetadata";
type Language = "zh" | "en" | "ja";
interface SaveResult {
requiresRestart: boolean;
}
@@ -402,11 +400,8 @@ export function useSettings(): UseSettingsResult {
);
try {
if (typeof window !== "undefined") {
window.localStorage.setItem(
"language",
payload.language as Language,
);
if (typeof window !== "undefined" && payload.language) {
window.localStorage.setItem("language", payload.language);
}
} catch (error) {
console.warn(