mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 00:35:32 +08:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user