Skip to content

Commit 4124c77

Browse files
committed
fix: preserve Settings Editor TOC section state across focus changes (fixes PlatformNetwork/bounty-challenge#21908)
1 parent c898c14 commit 4124c77

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/components/settings/SettingsEditor.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { useWorkspaceTrust } from "@/context/WorkspaceTrustContext";
3434
import { isSettingRestricted, getSettingRestrictionReason } from "@/utils/restrictedSettings";
3535
import { tokens } from "@/design-system/tokens";
3636
import { Button, IconButton, Input, Text, Badge, Toggle } from "@/components/ui";
37+
import { safeGetItem, safeSetItem } from "@/utils/safeStorage";
3738
import { loadStylesheet } from "@/utils/lazyStyles";
3839
loadStylesheet("settings");
3940

@@ -105,8 +106,17 @@ interface FilterSuggestion {
105106
description: string;
106107
}
107108

108-
// Module-level signal to persist TOC section across re-renders / focus changes
109-
const [persistedActiveSection, setPersistedActiveSection] = createSignal("editor");
109+
// Module-level signal to persist TOC section across re-renders / focus changes.
110+
// Back the signal with sessionStorage so the value survives lazy-chunk re-evaluation
111+
// and component unmount/remount cycles (e.g. switching editor tabs).
112+
const SETTINGS_TOC_STORAGE_KEY = "settings_active_toc_section";
113+
const [persistedActiveSection, _setPersistedRaw] = createSignal(
114+
safeGetItem(SETTINGS_TOC_STORAGE_KEY) || "editor"
115+
);
116+
const setPersistedActiveSection = (id: string) => {
117+
_setPersistedRaw(id);
118+
safeSetItem(SETTINGS_TOC_STORAGE_KEY, id);
119+
};
110120

111121
// =============================================================================
112122
// SETTINGS REGISTRY

src/components/settings/__tests__/SettingsEditor.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ vi.mock("@/context/SettingsContext", () => {
1919
enabled: true, fontSize: 0, fontFamily: "", showTypes: true,
2020
showParameterNames: true, showReturnTypes: true, maxLength: 25, padding: false,
2121
},
22+
semanticHighlighting: { enabled: true, strings: true, comments: true },
2223
},
2324
theme: {
2425
theme: "dark", iconTheme: "seti", accentColor: "#007acc", uiFontFamily: "Inter",
@@ -110,6 +111,12 @@ vi.mock("@/utils/restrictedSettings", () => ({
110111
getSettingRestrictionReason: () => null,
111112
}));
112113

114+
vi.mock("@/utils/safeStorage", () => ({
115+
safeGetItem: () => null,
116+
safeSetItem: () => {},
117+
safeRemoveItem: () => {},
118+
}));
119+
113120
vi.mock("@/utils/lazyStyles", () => ({
114121
loadStylesheet: () => {},
115122
}));

0 commit comments

Comments
 (0)