fix(uns): guard ScriptedAlarmModal form rebuild against stray re-renders (code-review)
This commit is contained in:
@@ -137,8 +137,25 @@
|
|||||||
private bool _busy;
|
private bool _busy;
|
||||||
private string? _error;
|
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()
|
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.
|
// Rebuild the working form whenever the host (re)opens the modal for a fresh target.
|
||||||
if (IsNew)
|
if (IsNew)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user