diff --git a/src/App.tsx b/src/App.tsx index 2160bca..242c3a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -85,7 +85,11 @@ const MainApp: React.FC = () => { (window.ForceTheme as string) !== "" ? window.ForceTheme : undefined; useEffect(() => { - if (forceTheme === "dark" || forceTheme === "light") { + const savedTheme = localStorage.getItem("vite-ui-theme"); + if ( + (!savedTheme || savedTheme === "system") && + (forceTheme === "dark" || forceTheme === "light") + ) { setTheme(forceTheme); } }, [forceTheme, setTheme]); diff --git a/src/components/DashCommand.tsx b/src/components/DashCommand.tsx index 14ce314..c972f4f 100644 --- a/src/components/DashCommand.tsx +++ b/src/components/DashCommand.tsx @@ -91,6 +91,8 @@ export function DashCommand() { return ( { - localStorage.setItem(storageKey, theme); - setTheme(theme); + const handleSetTheme = useCallback( + (nextTheme: Theme) => { + localStorage.setItem(storageKey, nextTheme); + setTheme(nextTheme); }, - }; + [storageKey], + ); + + const value = useMemo( + () => ({ + theme, + setTheme: handleSetTheme, + }), + [theme, handleSetTheme], + ); return ( diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx index 0ce02c6..fd5c327 100644 --- a/src/components/ui/command.tsx +++ b/src/components/ui/command.tsx @@ -46,6 +46,8 @@ const CommandInput = React.forwardRef< { - // 只有在 status 改变时才触发,避免无限循环 - const currentStatus = status || "all"; - if (currentStatus !== "all" || activeView === "domains") { - setActiveView("servers"); + if (prevStatusRef.current !== status) { + prevStatusRef.current = status; + if (activeView === "domains") { + setActiveView("servers"); + } } }, [status, activeView]); @@ -586,6 +587,8 @@ export default function Servers({