diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/ScriptLog.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/ScriptLog.razor index 08192305..b603d9c4 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/ScriptLog.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/ScriptLog.razor @@ -118,10 +118,15 @@ else // Live tail straight from the in-process broadcaster (fed by ScriptLogSignalRBridge off the // 'script-logs' DPS topic). Blazor Server can't self-connect a SignalR HubConnection behind // a reverse proxy — see IInProcessBroadcaster — so we subscribe in-process instead. + // Subscribe the state-change event BEFORE reading IsConnected so no transition is missed. + ScriptLogs.ConnectionStateChanged += OnConnectionStateChanged; ScriptLogs.Received += OnEntry; - _connected = true; + _connected = ScriptLogs.IsConnected; } + private void OnConnectionStateChanged(bool connected) => + InvokeAsync(() => { _connected = connected; StateHasChanged(); }); + private void OnEntry(ScriptLogEntry entry) => // Marshal both the mutation and the re-render onto the circuit sync context so this can't // race ClearAsync (which runs there) over the shared _rows list. @@ -146,5 +151,9 @@ else _ => "chip-idle", }; - public void Dispose() => ScriptLogs.Received -= OnEntry; + public void Dispose() + { + ScriptLogs.ConnectionStateChanged -= OnConnectionStateChanged; + ScriptLogs.Received -= OnEntry; + } }