From f446047f8b75bf60675f548e8f8a5e51209dcc63 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Fri, 2 May 2025 00:53:42 +0300 Subject: [PATCH] test(Player): fix binge watching (6) --- src/routes/Player/Player.js | 53 +++++++------------------------------ 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/src/routes/Player/Player.js b/src/routes/Player/Player.js index 6fb5b02c8..285f54a28 100644 --- a/src/routes/Player/Player.js +++ b/src/routes/Player/Player.js @@ -85,6 +85,8 @@ const Player = ({ urlParams, queryParams }) => { const nextVideoHandledRef = React.useRef(false); const nextVideoPopupDismissed = React.useRef(false); + const nextVideoInitialData = React.useRef(player.nextVideo); + nextVideoInitialData.current = player.nextVideo; const defaultSubtitlesSelected = React.useRef(false); const defaultAudioTrackSelected = React.useRef(false); const [error, setError] = React.useState(null); @@ -103,6 +105,7 @@ const Player = ({ urlParams, queryParams }) => { }, [settings.subtitlesSize, settings.subtitlesOffset, settings.subtitlesTextColor, settings.subtitlesBackgroundColor, settings.subtitlesOutlineColor]); const onEnded = React.useCallback(() => { + player.nextVideo = nextVideoInitialData.current; ended(); if (player.nextVideo !== null) { onNextVideoRequested(); @@ -216,35 +219,13 @@ const Player = ({ urlParams, queryParams }) => { const onNextVideoRequested = React.useCallback(() => { if (player.nextVideo !== null) { - // Call nextVideo only for analytics nextVideo(); - - // Capture navigation data - const navigationLink = player.nextVideo.deepLinks.player || - player.nextVideo.deepLinks.metaDetailsStreams; - - if (navigationLink) { - // Force immediate navigation with no chance of React re-renders affecting it - // This bypasses the React lifecycle entirely - const navigateImmediately = () => { - const form = document.createElement('form'); - form.style.display = 'none'; - form.method = 'GET'; - form.action = navigationLink; - - const input = document.createElement('input'); - input.type = 'hidden'; - input.name = 'navigationFromPlayer'; - input.value = 'true'; - form.appendChild(input); - - // Force immediate navigation - document.body.appendChild(form); - form.submit(); - }; - - // Execute immediately - navigateImmediately(); + const deepLinks = player.nextVideo.deepLinks; + if (deepLinks.metaDetailsStreams && deepLinks.player) { + window.location.replace(deepLinks.metaDetailsStreams); + window.location.href = deepLinks.player; + } else { + window.location.replace(deepLinks.player ?? deepLinks.metaDetailsStreams); } } }, [player.nextVideo]); @@ -657,22 +638,6 @@ const Player = ({ urlParams, queryParams }) => { }; }, []); - React.useEffect(() => { - const urlParams = new URLSearchParams(window.location.search); - // eslint-disable-next-line - const cameFromPlayer = urlParams.get('navigationFromPlayer'); - - if (cameFromPlayer === 'true') { - // eslint-disable-next-line - urlParams.delete('navigationFromPlayer'); - const newUrl = window.location.pathname + - (urlParams.toString() ? '?' + urlParams.toString() : '') + - window.location.hash; - - window.history.replaceState({}, '', newUrl); - } - }, []); - return (