fix(uns): guard ScriptedAlarmModal form rebuild against stray re-renders (code-review)

This commit is contained in:
Joseph Doherty
2026-06-11 15:03:43 -04:00
parent 826ffdc1a0
commit f1b9e7116b
@@ -137,8 +137,25 @@
private bool _busy;
private string? _error;
// Tracks which open this modal last loaded for, so unrelated Blazor Server re-renders don't
// rebuild _form and clobber in-progress edits. Null while closed.
private string? _loadedKey;
protected override void OnParametersSet()
{
if (!Visible)
{
_loadedKey = null; // closed → next open reloads fresh
return;
}
// Guard against unrelated re-renders. In Blazor Server any live-status push re-invokes
// OnParametersSet; without this the rebuild below would silently discard whatever the
// operator has typed. Only rebuild when the modal OPENS or the target entity CHANGES.
var key = IsNew ? "<new>" : Existing?.ScriptedAlarmId;
if (key == _loadedKey) return; // same open, re-render → preserve in-progress form edits
_loadedKey = key;
// Rebuild the working form whenever the host (re)opens the modal for a fresh target.
if (IsNew)
{