From 40cf2c29b73e27adecfac1ac62ca0bd8be1ec9bd Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Wed, 25 Mar 2026 13:30:58 -0500 Subject: [PATCH] fix: cleared input fields re-fill with stale draft text on re-render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- PolyPilot/Components/Pages/Dashboard.razor | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PolyPilot/Components/Pages/Dashboard.razor b/PolyPilot/Components/Pages/Dashboard.razor index 8008a499e3..4248434f72 100644 --- a/PolyPilot/Components/Pages/Dashboard.razor +++ b/PolyPilot/Components/Pages/Dashboard.razor @@ -1102,7 +1102,7 @@ var result = {}; var active = document.activeElement; document.querySelectorAll('.card-input input, .card-input textarea, .expanded-card .input-area textarea').forEach(function(el) { - if (el.id && el.value) result[el.id] = el.value; + if (el.id) result[el.id] = el.value || ''; }); if (active && active.id) result['__focused'] = active.id; if (active) { result['__selStart'] = active.selectionStart || 0; result['__selEnd'] = active.selectionEnd || 0; } @@ -1120,6 +1120,8 @@ var sessionName = id.Replace("input-", "").Replace("-", " "); if (!string.IsNullOrEmpty(val)) draftBySession[sessionName] = val; + else + draftBySession.Remove(sessionName); } if (saved.TryGetValue("__focused", out var fid)) _focusedInputId = fid;