diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/DebugView.razor b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/DebugView.razor index b5a041ca..dff73ec0 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/DebugView.razor +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/DebugView.razor @@ -421,15 +421,31 @@ { _selectedSiteId = siteId; await LoadInstancesForSite(); + + // Membership guard, mirroring the ?instanceId= path above. A stored instance that + // has since been disabled (or deleted, or moved to another site) is not in the list + // the picker was handed, so it renders a blank field while the page holds a non-zero + // id and auto-connects to it anyway. Forget the stored instance instead — the site + // stays selected and loaded, so the operator just picks again. + var stored = _siteInstances.FirstOrDefault(i => i.Id == instanceId); + if (stored == null) + { + await JS.InvokeVoidAsync("localStorage.removeItem", "debugView.instanceId"); + _toast.ShowInfo( + "The instance from your previous session is no longer available for debug streaming.", + autoDismissMs: 8000); + StateHasChanged(); + return; + } + _selectedInstanceId = instanceId; _connectedFromStorage = true; StateHasChanged(); await Connect(); // Auto-reconnect notice — the user didn't initiate this connection. - var inst = _siteInstances.FirstOrDefault(i => i.Id == instanceId); _toast.ShowInfo( - $"Auto-reconnected to {inst?.UniqueName ?? "instance"} from previous session.", + $"Auto-reconnected to {stored.UniqueName} from previous session.", autoDismissMs: 8000); } } diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/FlowDebugger.razor.cs b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/FlowDebugger.razor.cs index 9e98afb1..0c9608b9 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/FlowDebugger.razor.cs +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Deployment/FlowDebugger.razor.cs @@ -447,9 +447,9 @@ public partial class FlowDebugger : ComponentBase, IDisposable return; } - _instances = (await TemplateEngineRepository.GetInstancesBySiteIdAsync(_selectedSiteId)) - .OrderBy(i => i.UniqueName, StringComparer.OrdinalIgnoreCase).ToList(); - // The picker nests these itself (InstanceTreeBuilder), so order does not matter here. + // Neither list is sorted here: the picker nests and orders both itself + // (InstanceTreeBuilder). The OrderBy this replaces dated from the flat