Skip to content

Commit 9474aef

Browse files
lidge-junclaude
andcommitted
[agent] fix: persist active page in URL hash across reload
Cmd+R / Cmd+Shift+R was resetting to Dashboard because page state was useState("dashboard"). Now reads from location.hash on init, updates hash on navigate, and listens for hashchange (back/forward). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7cf064c commit 9474aef

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

gui/src/App.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import { useI18n, useT, LOCALES, type TKey } from "./i18n";
1111
type Page = "dashboard" | "providers" | "models" | "subagents" | "logs" | "codex-auth";
1212
type Theme = "light" | "dark" | "system";
1313

14+
const VALID_PAGES = new Set<Page>(["dashboard", "providers", "models", "subagents", "logs", "codex-auth"]);
15+
16+
function readPageFromHash(): Page {
17+
const raw = location.hash.replace(/^#\/?/, "");
18+
return VALID_PAGES.has(raw as Page) ? (raw as Page) : "dashboard";
19+
}
20+
1421
const API_BASE = import.meta.env.VITE_API_BASE || "";
1522
const THEME_KEY = "ocx-theme";
1623

@@ -38,14 +45,19 @@ function readStoredTheme(): Theme {
3845
}
3946

4047
export default function App() {
41-
const [page, setPage] = useState<Page>("dashboard");
48+
const [page, setPageState] = useState<Page>(readPageFromHash);
49+
const setPage = (p: Page) => { location.hash = p; setPageState(p); };
4250
const [theme, setTheme] = useState<Theme>(readStoredTheme);
4351
const [runtimeVersion, setRuntimeVersion] = useState<string | null>(null);
4452
const { locale, setLocale } = useI18n();
4553
const t = useT();
4654

47-
// Pin color-scheme via [data-theme]; "system" clears it so the OS preference applies (matches the
48-
// FOWT guard in index.html). Persisted so the choice survives reloads.
55+
useEffect(() => {
56+
const onHash = () => setPageState(readPageFromHash());
57+
window.addEventListener("hashchange", onHash);
58+
return () => window.removeEventListener("hashchange", onHash);
59+
}, []);
60+
4961
useEffect(() => {
5062
const el = document.documentElement;
5163
if (theme === "system") { el.removeAttribute("data-theme"); localStorage.removeItem(THEME_KEY); }

0 commit comments

Comments
 (0)