diff --git a/src/Aspire.Dashboard/Components/Pages/ResourceLogsBase.razor.cs b/src/Aspire.Dashboard/Components/Pages/ResourceLogsBase.razor.cs index 4a10ec326e..b960a24244 100644 --- a/src/Aspire.Dashboard/Components/Pages/ResourceLogsBase.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/ResourceLogsBase.razor.cs @@ -43,35 +43,43 @@ protected abstract IAsyncEnumerable> WatchResources( private CancellationTokenSource? _watchLogsTokenSource; private string _status = LogStatus.Initializing; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { _status = LoadingResourcesMessage; + } - var initialList = await GetResources(DashboardViewModelService); - - foreach (var result in initialList) - { - _resourceNameMapping[result.Name] = result; - } - - if (ResourceName is not null) - { - _selectedResource = initialList.FirstOrDefault(c => string.Equals(ResourceName, c.Name, StringComparison.Ordinal)); - } - else if (initialList.Count > 0) + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) { - _selectedResource = initialList[0]; - } + var initialList = await GetResources(DashboardViewModelService); - await LoadLogsAsync(); + foreach (var result in initialList) + { + _resourceNameMapping[result.Name] = result; + } - _ = Task.Run(async () => - { - await foreach (var resourceChanged in WatchResources(DashboardViewModelService, initialList.Select(t => t.NamespacedName), _watchContainersTokenSource.Token)) + if (ResourceName is not null) + { + _selectedResource = initialList.FirstOrDefault(c => string.Equals(ResourceName, c.Name, StringComparison.Ordinal)); + } + else if (initialList.Count > 0) { - await OnResourceListChangedAsync(resourceChanged.ObjectChangeType, resourceChanged.Resource); + _selectedResource = initialList[0]; } - }); + + await LoadLogsAsync(); + + _ = Task.Run(async () => + { + await foreach (var resourceChanged in WatchResources(DashboardViewModelService, initialList.Select(t => t.NamespacedName), _watchContainersTokenSource.Token)) + { + await OnResourceListChangedAsync(resourceChanged.ObjectChangeType, resourceChanged.Resource); + } + }); + + StateHasChanged(); + } } private Task ClearLogsAsync()