fix(adminui,client): error boundary inside the interactive scope, stale-commit OnSaved, AbCip browse delay emit, DisposeBridge cancel (review R3)

M1: PageErrorBoundary wraps the body of every InteractiveServer page; the inert layout boundary is removed.
m1: DisposeBridge cancels its CTS when the 5 s wait times out.
m2: a CSV import that commits after the modal closed still raises OnSaved.
m3: document SecurityMode=None no-fallback in Client.CLI.md / Client.UI.md.
m4: browsePageDelayMs written only when loaded or changed; negative flagged.

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-08 07:31:19 -04:00
parent ca0f1e7735
commit 1475991fd6
39 changed files with 478 additions and 48 deletions
@@ -49,7 +49,11 @@
<div class="col-md-3">
<label class="form-label" for="abcipBrowsePageDelay">Browse page delay (ms)</label>
<InputNumber @bind-Value="_form.BrowsePageDelayMs" @bind-Value:after="EmitAsync" class="form-control form-control-sm" id="abcipBrowsePageDelay" />
<div class="form-text">Pause between controller symbol-browse pages (<code>browsePageDelayMs</code>). Default 5 ms; 0 disables the pause.</div>
<div class="form-text">Pause between controller symbol-browse pages (<code>browsePageDelayMs</code>). Default 5 ms; 0 disables the pause. Left at the default on a config that never set it, the key is not written.</div>
@if (_form.BrowsePageDelayError is { } browseDelayError)
{
<div class="text-danger small mt-1" id="abcipBrowsePageDelayError">@browseDelayError</div>
}
</div>
</div>
</div>
@@ -181,14 +185,29 @@
/// Devices array forward (the device form authors the real endpoints; the merge reconstructs the array
/// from the device rows at deploy/probe time).</summary>
public string GetConfigJson()
=> Serialize(_form.ToOptions(_preservedDevices), _originalJson);
=> Serialize(_form.ToOptions(_preservedDevices), _originalJson, _form.EmitsBrowsePageDelay);
/// <summary>Serializes options with the form's JSON settings (camelCase, enums as strings).</summary>
internal static string Serialize(AbCipDriverOptions options, string? originalJson = null)
=> DriverConfigJsonOverlay.Apply(originalJson, JsonSerializer.Serialize(options, _jsonOpts), OwnedPaths, TimeSpanToMs);
/// <param name="options">The form's options.</param>
/// <param name="originalJson">The stored config, so unmodelled keys survive.</param>
/// <param name="emitBrowsePageDelay">
/// False omits <c>browsePageDelayMs</c> from the saved config (it was never set and the operator left the
/// default), so a later change of the factory default is not pinned by an unrelated AdminUI save.
/// </param>
internal static string Serialize(AbCipDriverOptions options, string? originalJson = null, bool emitBrowsePageDelay = true)
{
var json = DriverConfigJsonOverlay.Apply(originalJson, JsonSerializer.Serialize(options, _jsonOpts), OwnedPaths, TimeSpanToMs);
if (emitBrowsePageDelay || System.Text.Json.Nodes.JsonNode.Parse(json) is not System.Text.Json.Nodes.JsonObject obj) return json;
var key = obj.Select(kv => kv.Key).FirstOrDefault(k => string.Equals(k, "browsePageDelayMs", StringComparison.OrdinalIgnoreCase));
if (key is not null) obj.Remove(key);
return obj.ToJsonString();
}
private async Task EmitAsync()
{
// An invalid value is shown inline and NOT emitted: the saved config must never differ silently from
// what the field displays (ToOptions would clamp a negative to 0).
if (_form.BrowsePageDelayError is not null) return;
var json = GetConfigJson();
_lastParsed = json;
_originalJson = json;
@@ -221,7 +240,16 @@
public bool EnableControllerBrowse { get; set; } = false;
public bool EnableDeclarationOnlyUdtGrouping { get; set; } = false;
// Milliseconds between controller symbol-browse pages (factory key browsePageDelayMs; default 5).
public int BrowsePageDelayMs { get; set; } = 5;
public const int DefaultBrowsePageDelayMs = 5;
public int BrowsePageDelayMs { get; set; } = DefaultBrowsePageDelayMs;
// True when the stored config carried the key; with the default value and no key, it stays absent.
private bool _browsePageDelayLoaded;
/// <summary>Whether the save should write <c>browsePageDelayMs</c>: it was loaded, or differs from the default.</summary>
public bool EmitsBrowsePageDelay => _browsePageDelayLoaded || BrowsePageDelayMs != DefaultBrowsePageDelayMs;
/// <summary>A validation message for the browse page delay, or null when valid.</summary>
public string? BrowsePageDelayError => BrowsePageDelayMs < 0 ? "Browse page delay must be 0 or greater." : null;
// Alarm projection
public bool EnableAlarmProjection { get; set; } = false;
@@ -248,7 +276,9 @@
f._loadedAlarmPoll = Ms(json, "alarmPollIntervalMs") ?? f._loadedAlarmPoll;
f._loadedProbeInterval = Ms(json, "probe.intervalMs") ?? f._loadedProbeInterval;
f._loadedProbeTimeout = Ms(json, "probe.timeoutMs") ?? f._loadedProbeTimeout;
f.BrowsePageDelayMs = DriverConfigMs.Read(json, "browsePageDelayMs") ?? f.BrowsePageDelayMs;
var browseDelay = DriverConfigMs.Read(json, "browsePageDelayMs");
f._browsePageDelayLoaded = browseDelay.HasValue;
f.BrowsePageDelayMs = browseDelay ?? f.BrowsePageDelayMs;
f.TimeoutSeconds = DriverConfigMs.ToSeconds(f._loadedTimeout ?? o.Timeout);
f.AlarmPollIntervalSeconds = DriverConfigMs.ToSeconds(f._loadedAlarmPoll ?? o.AlarmPollInterval);
f.ProbeIntervalSeconds = DriverConfigMs.ToSeconds(f._loadedProbeInterval ?? o.Probe.Interval);
@@ -0,0 +1,45 @@
@implements IDisposable
@* Confines an exception thrown while rendering or handling an event on a page to the page body, instead
of killing the whole Blazor circuit (the blank "reload" bar).
WHERE IT MAY LIVE: this host's <Routes/> is static SSR, so MainLayout renders statically and every
@rendermode InteractiveServer page is its OWN interactive root, not a child of anything in the layout.
A boundary in the layout therefore never sees a page failure and its Recover/navigation handlers are
dead. The boundary has to sit INSIDE the interactive root — i.e. each interactive page wraps its body
in <PageErrorBoundary>. Pinned by AdminUiFormSweepGuardTests (every interactive page wraps) and
PageErrorBoundaryTests (the component really contains a throw and recovers).
It does NOT catch exceptions from async-void handlers or timer callbacks. *@
<ErrorBoundary @ref="_boundary">
<ChildContent>@ChildContent</ChildContent>
<ErrorContent Context="ex">
<div class="alert alert-danger m-3" role="alert" data-testid="page-error-boundary">
<strong>This page hit an unexpected error.</strong>
<div class="small mono mt-1">@ex.GetType().Name: @ex.Message</div>
<button type="button" class="btn btn-sm btn-outline-danger mt-2" @onclick="Recover">Try again</button>
</div>
</ErrorContent>
</ErrorBoundary>
@code {
private ErrorBoundary? _boundary;
[Parameter] public RenderFragment? ChildContent { get; set; }
[Inject] private NavigationManager Nav { get; set; } = default!;
protected override void OnInitialized() => Nav.LocationChanged += OnLocationChanged;
/// <summary>Clears a tripped boundary and re-renders the wrapped content.</summary>
public void Recover() => _boundary?.Recover();
// A fresh navigation (e.g. same page, new route parameters, where the component instance is reused)
// clears a tripped boundary so the new location isn't stuck behind the old error. InvokeAsync keeps
// the Recover on the renderer's dispatcher.
private void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
=> _ = InvokeAsync(Recover);
/// <inheritdoc/>
public void Dispose() => Nav.LocationChanged -= OnLocationChanged;
}
@@ -305,7 +305,13 @@
.ToList();
var outcome = await Svc.ImportTagsAsync(targetDeviceId, rows);
if (IsStale(generation)) { return; }
// The write has landed whether or not the modal was closed/reopened meanwhile, so the parent must
// still refresh its tree; only the modal-local state writes are skipped when stale.
if (IsStale(generation))
{
if (outcome.Errors.Count == 0) { await OnSaved.InvokeAsync(); }
return;
}
if (outcome.Errors.Count > 0)
{
_commitErrors = outcome.Errors.ToList();