diff --git a/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host-races.spec.ts b/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host-races.spec.ts index eee98109c..f405b9aa6 100644 --- a/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host-races.spec.ts +++ b/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host-races.spec.ts @@ -86,6 +86,27 @@ describe('VodMultiSourceHostService — stale resolutions', () => { ); }); + it('drops a switch once the movie identity goes null mid-navigation', async () => { + await loadMovie([ALT_TWO]); + + const slow = createDeferred>(); + resolver.resolve.mockReturnValueOnce(slow.promise); + + const pending = service.play(ALT_TWO.id); + + // Route navigation empties the identity BEFORE the next movie's load() + // runs. Without invalidating the session here, the guard would still + // pass and the old movie's source would start over the new page. + movie.set(null); + TestBed.tick(); + + slow.resolve(resolvedFor(ALT_TWO, 0)); + await expect(pending).resolves.toBe(false); + + expect(startPlayback).not.toHaveBeenCalled(); + expect(rowFor(ALT_TWO.id)?.isActive).toBe(false); + }); + it('drops a slower switch that a newer selection already superseded', async () => { await loadMovie([ALT_TWO, ALT_THREE]); diff --git a/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host.service.ts b/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host.service.ts index 9c7553568..239f53340 100644 --- a/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host.service.ts +++ b/libs/portal/xtream/feature/src/lib/vod-details/vod-multi-source-host.service.ts @@ -146,6 +146,12 @@ export class VodMultiSourceHostService { effect(() => { const movie = bindings.movie(); if (!movie) { + // Navigating away empties the identity before the next movie's + // `load()` runs. Bumping the session here — not only in + // `load()` — closes the window in which a resolution still in + // flight for the PREVIOUS movie would pass the staleness guard + // and start its playback over the page the user is leaving. + this.discoveryToken++; return; }