Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 36 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,10 @@ const PromptsSettings = ({
const [testPrompt, setTestPrompt] = useState("")
const [isEnhancing, setIsEnhancing] = useState(false)
const [activeSupportOption, setActiveSupportOption] = useState<SupportPromptType>("ENHANCE")
// kilocode_change start
// Local state for condensing prompt to prevent flickering during typing
const [localCondensingPrompt, setLocalCondensingPrompt] = useState<string | undefined>(undefined)
// kilocode_change end

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

// kilocode_change start
// 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.

// kilocode_change end

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 +133,11 @@ 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
// kilocode_change start
// Use local state during editing to prevent flickering
// Fall back to extension state, then to default
return localCondensingPrompt ?? customCondensingPrompt ?? supportPrompt.default.CONDENSE
// kilocode_change end
}
return supportPrompt.get(customSupportPrompts, type)
}
Expand Down Expand Up @@ -186,8 +202,26 @@ const PromptsSettings = ({
const value =
(e as unknown as CustomEvent)?.detail?.target?.value ??
((e as any).target as HTMLTextAreaElement).value
// kilocode_change start
// For CONDENSE, update local state immediately to prevent flickering
if (activeSupportOption === "CONDENSE") {
setLocalCondensingPrompt(value)
}
// kilocode_change end
updateSupportPrompt(activeSupportOption, value)
}}
// kilocode_change start
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)
}
}}
// kilocode_change end
rows={6}
className="w-full"
/>
Expand Down
Loading