Skip to content

Commit 36dbc33

Browse files
fix(settings): restore immediate persistence for uncontrolled includeTaskHistoryInEnhance
The previous Save-buffering change dropped the updateSettings post unconditionally, which fixed the controlled path but broke the uncontrolled one: with props omitted the toggle falls back to the context setter, which only updates local state and never persists. Gate the post on whether the component is controlled: - Controlled: setter buffers into cachedState, Save persists — no post here. - Uncontrolled: context setter is local-only, so post updateSettings now. Mirrors the props-first / context-fallback pattern used for McpEnabledToggle. Adds an uncontrolled regression test (updates local state *and* posts), symmetric with the controlled "buffer only" case. Signed-off-by: JunyongParkDev <[email protected]>
1 parent 53ad0e9 commit 36dbc33

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎webview-ui/src/components/settings/PromptsSettings.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ const PromptsSettings = ({
208208
}
209209

210210
setIncludeTaskHistoryInEnhance(target.checked)
211+
212+
// Controlled: setter buffers into cachedState (Save persists).
213+
// Uncontrolled: context setter is local-only, so persist here.
214+
if (!propsSetIncludeTaskHistoryInEnhance) {
215+
vscode.postMessage({
216+
type: "updateSettings",
217+
updatedSettings: {
218+
includeTaskHistoryInEnhance: target.checked,
219+
},
220+
})
221+
}
211222
}}>
212223
<span className="font-medium">
213224
{t("prompts:supportPrompts.enhance.includeTaskHistory")}

‎webview-ui/src/components/settings/__tests__/PromptsSettings.spec.tsx‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ vi.mock("@src/i18n/TranslationContext", () => ({
1515
useAppTranslation: () => ({ t: (key: string) => key }),
1616
}))
1717

18-
// PromptsSettings falls back to context when props are absent; we always pass
19-
// props here (the SettingsView wiring), so the context values are inert.
18+
// Exposed so tests can assert the context (uncontrolled) setter still fires.
19+
const { contextSetIncludeTaskHistoryInEnhance } = vi.hoisted(() => ({
20+
contextSetIncludeTaskHistoryInEnhance: vi.fn(),
21+
}))
22+
23+
// PromptsSettings falls back to context when props are absent.
2024
vi.mock("@src/context/ExtensionStateContext", () => ({
2125
useExtensionState: () => ({
2226
listApiConfigMeta: [],
2327
enhancementApiConfigId: "",
2428
setEnhancementApiConfigId: vi.fn(),
2529
includeTaskHistoryInEnhance: true,
26-
setIncludeTaskHistoryInEnhance: vi.fn(),
30+
setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance,
2731
}),
2832
}))
2933

@@ -59,4 +63,29 @@ describe("PromptsSettings - Save/Discard contract", () => {
5963
expect(setIncludeTaskHistoryInEnhance).toHaveBeenCalledWith(false)
6064
expect(vscode.postMessage).not.toHaveBeenCalledWith(expect.objectContaining({ type: "updateSettings" }))
6165
})
66+
67+
// Uncontrolled usage (props omitted) has no cachedState/Save wiring, so the
68+
// toggle must persist immediately via updateSettings — otherwise it is lost.
69+
it("persists includeTaskHistoryInEnhance immediately when used uncontrolled", () => {
70+
render(
71+
<PromptsSettings
72+
customSupportPrompts={{}}
73+
setCustomSupportPrompts={vi.fn()}
74+
// includeTaskHistoryInEnhance / setIncludeTaskHistoryInEnhance omitted → context fallback
75+
/>,
76+
)
77+
78+
const checkbox = screen
79+
.getByText("prompts:supportPrompts.enhance.includeTaskHistory")
80+
.closest("label")!
81+
.querySelector('input[type="checkbox"]')!
82+
fireEvent.click(checkbox)
83+
84+
// Still updates local (context) state, and also persists immediately.
85+
expect(contextSetIncludeTaskHistoryInEnhance).toHaveBeenCalledWith(false)
86+
expect(vscode.postMessage).toHaveBeenCalledWith({
87+
type: "updateSettings",
88+
updatedSettings: { includeTaskHistoryInEnhance: false },
89+
})
90+
})
6291
})

0 commit comments

Comments
 (0)