From 0fa2e91afc64992a718268c1e6e6e01f45bd064c Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 15 Aug 2025 20:58:43 +0200 Subject: [PATCH] Fix debounce timer setup and synchronization logic in DebouncedTextField component --- .../Components/DebouncedTextField.razor.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs b/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs index 41b26d93..3ad55c6a 100644 --- a/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs +++ b/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs @@ -51,6 +51,7 @@ public partial class DebouncedTextField : MudComponentBase, IDisposable private readonly Timer debounceTimer = new(); private string text = string.Empty; private string lastParameterText = string.Empty; + private bool isInitialized; #region Overrides of ComponentBase @@ -68,21 +69,29 @@ public partial class DebouncedTextField : MudComponentBase, IDisposable this.InvokeAsync(() => this.WhenTextCanged(this.text)); }; + this.isInitialized = true; await base.OnInitializedAsync(); } protected override async Task OnParametersSetAsync() { + // Ensure the timer uses the latest debouncing interval: + if (!this.isInitialized) + return; + + if(Math.Abs(this.debounceTimer.Interval - this.DebounceTime.TotalMilliseconds) > 1) + this.debounceTimer.Interval = this.DebounceTime.TotalMilliseconds; + // Only sync when the parent's parameter actually changed since the last change: if (this.Text != this.lastParameterText) { this.text = this.Text; this.lastParameterText = this.Text; - - this.debounceTimer.Stop(); - this.debounceTimer.Start(); } + this.debounceTimer.Stop(); + this.debounceTimer.Start(); + await base.OnParametersSetAsync(); }