Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-condensing-prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Fix context condensing prompt not saving properly
28 changes: 26 additions & 2 deletions webview-ui/src/components/settings/PromptsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const PromptsSettings = ({
const [testPrompt, setTestPrompt] = useState("")
const [isEnhancing, setIsEnhancing] = useState(false)
const [activeSupportOption, setActiveSupportOption] = useState<SupportPromptType>("ENHANCE")
// Local state for condensing prompt to prevent flickering during typing
const [localCondensingPrompt, setLocalCondensingPrompt] = useState<string | undefined>(undefined)

useEffect(() => {
const handler = (event: MessageEvent) => {
Expand All @@ -70,6 +72,13 @@ const PromptsSettings = ({
return () => window.removeEventListener("message", handler)
}, [])

// Initialize local condensing prompt when switching to CONDENSE tab
useEffect(() => {
if (activeSupportOption === "CONDENSE") {
setLocalCondensingPrompt(customCondensingPrompt)
}
}, [activeSupportOption, customCondensingPrompt])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WARNING]: Including customCondensingPrompt in this dependency array may undermine the anti-flickering protection.

When the user is actively typing, the flow is:

  1. onInputsetLocalCondensingPrompt(value) + updateSupportPrompt(...)setCustomCondensingPrompt(value) + vscode.postMessage(...)
  2. If the extension processes the message and sends back a different/normalized value (e.g., via ExtensionStateContext), customCondensingPrompt changes
  3. This useEffect fires and overwrites localCondensingPrompt with the extension's value — exactly the flickering scenario this PR aims to prevent

Consider depending only on activeSupportOption so the local state is initialized only when switching tabs, not overwritten during active editing:

Suggested change
}, [activeSupportOption, customCondensingPrompt])
}, [activeSupportOption]) // eslint-disable-line react-hooks/exhaustive-deps

Alternatively, you could use a ref to track whether the user is actively editing and skip the sync in that case.


const updateSupportPrompt = (type: SupportPromptType, value: string | undefined) => {
// Don't trim during editing to preserve intentional whitespace
// Use nullish coalescing to preserve empty strings
Expand Down Expand Up @@ -120,8 +129,9 @@ const PromptsSettings = ({

const getSupportPromptValue = (type: SupportPromptType): string => {
if (type === "CONDENSE") {
// Preserve empty string - only fall back to default when value is nullish
return customCondensingPrompt ?? supportPrompt.default.CONDENSE
// Use local state during editing to prevent flickering
// Fall back to extension state, then to default
return localCondensingPrompt ?? customCondensingPrompt ?? supportPrompt.default.CONDENSE
}
return supportPrompt.get(customSupportPrompts, type)
}
Expand Down Expand Up @@ -186,8 +196,22 @@ const PromptsSettings = ({
const value =
(e as unknown as CustomEvent)?.detail?.target?.value ??
((e as any).target as HTMLTextAreaElement).value
// For CONDENSE, update local state immediately to prevent flickering
if (activeSupportOption === "CONDENSE") {
setLocalCondensingPrompt(value)
}
updateSupportPrompt(activeSupportOption, value)
}}
onBlur={(e) => {
// For CONDENSE, sync with extension state on blur
if (activeSupportOption === "CONDENSE") {
const value =
(e as unknown as CustomEvent)?.detail?.target?.value ??
((e as any).target as HTMLTextAreaElement).value
setLocalCondensingPrompt(undefined)
updateSupportPrompt(activeSupportOption, value)
}
}}
rows={6}
className="w-full"
/>
Expand Down
Loading