diff --git a/PolyPilot/Components/ExpandedSessionView.razor b/PolyPilot/Components/ExpandedSessionView.razor index 5461e14b71..1f759932ff 100644 --- a/PolyPilot/Components/ExpandedSessionView.razor +++ b/PolyPilot/Components/ExpandedSessionView.razor @@ -683,6 +683,7 @@ private string? _prUrl; private string _prLabel = "PR"; private string? _lastPrCheckedDir; + private string? _lastExpandedSessionId; private List? availableSkills; private List? availableAgents; @@ -772,17 +773,37 @@ if (PlatformHelper.IsDesktop) { var dir = Session.WorkingDirectory; - if (!string.IsNullOrEmpty(dir) && dir != _lastPrCheckedDir) + var sessionSwitched = Session.SessionId != _lastExpandedSessionId; + _lastExpandedSessionId = Session.SessionId; + + if (sessionSwitched) + { + _prUrl = null; + _prLabel = "PR"; + } + + if (!string.IsNullOrEmpty(dir)) { - _lastPrCheckedDir = dir; - _ = FetchPrUrlAsync(dir); + if (dir != _lastPrCheckedDir) + { + _lastPrCheckedDir = dir; + _ = FetchPrUrlAsync(dir); + } + else if (sessionSwitched && _prUrl == null) + { + // Only re-check when user switches to this session, not on every render + _ = FetchPrUrlAsync(dir); + } } } } private async Task FetchPrUrlAsync(string dir) { - _prUrl = await PrLinkService.GetPrUrlForDirectoryAsync(dir); + var capturedId = Session.SessionId; + var url = await PrLinkService.GetPrUrlForDirectoryAsync(dir); + if (Session.SessionId != capturedId) return; + _prUrl = url; if (_prUrl != null) { var lastSlash = _prUrl.LastIndexOf('/'); diff --git a/PolyPilot/Components/Layout/SessionListItem.razor b/PolyPilot/Components/Layout/SessionListItem.razor index 6d1eda3cad..127fcc9789 100644 --- a/PolyPilot/Components/Layout/SessionListItem.razor +++ b/PolyPilot/Components/Layout/SessionListItem.razor @@ -352,15 +352,28 @@ private string _prLabel = "PR"; private string? _lastPrCheckedDir; private string? _renderSignature; + private bool _wasActive; protected override void OnParametersSet() { if (!PlatformHelper.IsDesktop) return; var dir = GetSessionDirectory(); - if (!string.IsNullOrEmpty(dir) && dir != _lastPrCheckedDir) + + // Re-check PR when session becomes active (user clicks it) and we don't have a PR yet + var becameActive = IsActive && !_wasActive; + _wasActive = IsActive; + + if (!string.IsNullOrEmpty(dir)) { - _lastPrCheckedDir = dir; - _ = FetchPrUrlAsync(dir); + if (dir != _lastPrCheckedDir) + { + _lastPrCheckedDir = dir; + _ = FetchPrUrlAsync(dir); + } + else if (becameActive && _prUrl == null) + { + _ = FetchPrUrlAsync(dir); + } } }