Skip to content

Commit 4f0bbac

Browse files
committed
fix: preserve Settings Editor TOC section state across focus changes (fixes PlatformNetwork/bounty-challenge#21908)
1 parent 954cd98 commit 4f0bbac

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ vi.mock("@/context/SettingsContext", () => {
1515
linkedEditing: false, stickyScrollEnabled: false, foldingEnabled: true,
1616
showFoldingControls: "mouseover", guidesIndentation: true, guidesBracketPairs: true,
1717
verticalTabs: false,
18+
inlayHints: {
19+
enabled: true, fontSize: 0, fontFamily: "", showTypes: true,
20+
showParameterNames: true, showReturnTypes: true, maxLength: 25, padding: false,
21+
},
22+
semanticHighlighting: { enabled: true, strings: true, comments: true },
1823
},
1924
theme: {
2025
theme: "dark", iconTheme: "seti", accentColor: "#007acc", uiFontFamily: "Inter",
@@ -96,6 +101,12 @@ vi.mock("@/utils/restrictedSettings", () => ({
96101
getSettingRestrictionReason: () => null,
97102
}));
98103

104+
vi.mock("@/utils/safeStorage", () => ({
105+
safeGetItem: () => null,
106+
safeSetItem: () => {},
107+
safeRemoveItem: () => {},
108+
}));
109+
99110
vi.mock("@/utils/lazyStyles", () => ({
100111
loadStylesheet: () => {},
101112
}));

0 commit comments

Comments
 (0)