diff --git a/libs/ui/playback/src/lib/web-player-view/web-player-recovery-policy.ts b/libs/ui/playback/src/lib/web-player-view/web-player-recovery-policy.ts index 75e8d727b..b5aba38fa 100644 --- a/libs/ui/playback/src/lib/web-player-view/web-player-recovery-policy.ts +++ b/libs/ui/playback/src/lib/web-player-view/web-player-recovery-policy.ts @@ -102,10 +102,7 @@ function revealCappedExternalSiblings( continue; } if (retained.length >= 3) { - const replaceIndex = retained.findLastIndex( - (recommendation, index) => - index > 0 && !isExternalRecommendation(recommendation) - ); + const replaceIndex = findLastReplaceableRecommendation(retained); if (replaceIndex < 0) { continue; } @@ -116,6 +113,17 @@ function revealCappedExternalSiblings( return retained; } +function findLastReplaceableRecommendation( + recommendations: readonly PlaybackRecommendation[] +): number { + for (let index = recommendations.length - 1; index > 0; index -= 1) { + if (!isExternalRecommendation(recommendations[index])) { + return index; + } + } + return -1; +} + function rerankExternalRecommendations( recommendations: readonly PlaybackRecommendation[], states: ExternalRecoveryStates