fix: cleared input fields re-fill with stale draft text on re-render#435
fix: cleared input fields re-fill with stale draft text on re-render#435
Conversation
The draft capture JS only saved inputs with truthy values: if (el.id && el.value) result[el.id] = el.value; When the user cleared an input, el.value was '' (falsy), so the empty value was never captured. But draftBySession still held the old text from a previous capture. On the next Blazor render cycle, restoreDraftsAndFocus re-applied the stale draft — putting the old text right back in the input field. Fix: 1. JS: Always capture the input value (even empty strings) 2. C#: Remove the session from draftBySession when captured value is empty, so restoreDraftsAndFocus won't re-apply stale text Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔍 Squad Review — PR #435 Round 1PR: fix: cleared input fields re-fill with stale draft text on re-render Root Cause & FixThe diagnosis is accurate and the fix is correct. The bug was a classic JS falsy-value trap:
Both sides of the fix are necessary and work together correctly. Findings
Debounce Gap Detail (F1)The var shouldCaptureDrafts = !_sessionSwitching
&& completedSessions.Count == 0
&& (nowTicks - lastCapture) >= 3000;Scenario where ghost text can still appear after this fix:
The debounce exists for good performance reason (multi-agent event bursts). The window is ≤3s and self-corrects on the next capture tick. Acceptable to ship as-is. SaveDraftsAndCursor Follow-up (F2)Easy to fix in a follow-up — apply the same remove-if-empty logic: // In SaveDraftsAndCursor, after draftBySession.Clear():
foreach (var item in state.Items ?? [])
{
var name = item.Id.Replace("input-", "").Replace("-", " ");
if (!string.IsNullOrEmpty(item.Value)) // add this guard
draftBySession[name] = item.Value;
// else: already cleared above, nothing to do
}Test Coverage AssessmentNo new tests added (this is JS interop + render-cycle code, hard to unit test at the unit level). The fix is simple enough that the logic is self-evident. A MauiDevFlow CDP integration test could cover the scenario but isn't required for merge. Verdict: ✅ ApproveThe core fix is correct and addresses the reported bug. F1 (debounce gap) is a pre-existing limitation and acceptable. F2 (SaveDraftsAndCursor inconsistency) is a clean-up that can be a fast follow-up — it won't cause regressions either way. F3 and F4 are cosmetic/minor. Verdicts by model: ✅ opus-1 · |
…435) ## Problem When a user clears text from a chat input field (backspace/select-all-delete), the old text immediately reappears on the next Blazor render cycle. Typing new text also gets overwritten by the stale draft. ## Root Cause The draft capture JS (line 1096) only saved inputs with **truthy** values: ```js if (el.id && el.value) result[el.id] = el.value; ``` When the user cleared an input, `el.value` was `""` (falsy), so the empty value was **never captured**. But `draftBySession` in C# still held the old text from a previous capture. On the next render, `restoreDraftsAndFocus` re-applied it. ## Fix 1. **JS**: Always capture input values, even empty strings 2. **C#**: Remove the session from `draftBySession` when captured value is empty Two lines changed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
When a user clears text from a chat input field (backspace/select-all-delete), the old text immediately reappears on the next Blazor render cycle. Typing new text also gets overwritten by the stale draft.
Root Cause
The draft capture JS (line 1096) only saved inputs with truthy values:
When the user cleared an input,
el.valuewas""(falsy), so the empty value was never captured. ButdraftBySessionin C# still held the old text from a previous capture. On the next render,restoreDraftsAndFocusre-applied it.Fix
draftBySessionwhen captured value is emptyTwo lines changed.