From 3f439e4277afc94199b2469ba9ca337503bcf68d Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Mon, 15 Jun 2026 12:18:05 -0700 Subject: [PATCH] video: fix back-button loop when a 'More Like This' item is owned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking a recommendation/cast/similar link to a title you OWN opens it via a tmdb URL that redirects to the library detail — but the redirect PUSHED a new history entry, so Back landed on the tmdb URL which redirected forward again => stuck loop + a self-referencing 'Back to ' label. The redirect now REPLACES the redirecting entry (keeping its layer + origin) instead of pushing, so Back unwinds cleanly to where you actually came from. --- webui/static/video/video-detail.js | 4 +++- webui/static/video/video-side.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/webui/static/video/video-detail.js b/webui/static/video/video-detail.js index 516dc182..1330752e 100644 --- a/webui/static/video/video-detail.js +++ b/webui/static/video/video-detail.js @@ -917,9 +917,11 @@ } // An owned title reached via a tmdb URL → bounce to the real library detail. + // _replace so it REPLACES the tmdb history entry (which would redirect again on + // Back) instead of pushing a new layer — otherwise Back loops on the redirect. function reopen(rd) { document.dispatchEvent(new CustomEvent('soulsync:video-open-detail', - { detail: { kind: rd.kind, id: rd.id, source: rd.source || 'library' } })); + { detail: { kind: rd.kind, id: rd.id, source: rd.source || 'library', _replace: true } })); } // Lazy: backfill a movie's cast/genres/art from TMDB on view if missing. diff --git a/webui/static/video/video-side.js b/webui/static/video/video-side.js index 602c367b..c893be2e 100644 --- a/webui/static/video/video-side.js +++ b/webui/static/video/video-side.js @@ -299,12 +299,19 @@ document.addEventListener('soulsync:video-open-detail', function (e) { var d = e && e.detail; if (!d) return; // Capture the origin BEFORE navigating away from the current page. - var origin = d._restore ? null : currentOrigin(); + var origin = (d._restore || d._replace) ? null : currentOrigin(); if (d.kind === 'movie') navigate('video-movie-detail'); else if (d.kind === 'show') navigate('video-show-detail'); else if (d.kind === 'person') navigate('video-person-detail'); else return; - if (!d._restore) { + if (d._replace) { + // A redirect (e.g. a tmdb link that's actually owned) → replace the + // entry being redirected FROM, keeping its layer + origin, so Back + // doesn't bounce back onto the redirecting URL. + var rstate = { videoDetail: { kind: d.kind, id: d.id, source: d.source || 'library', + layer: _backStack.length } }; + try { history.replaceState(rstate, '', buildDetailPath(d.source, d.kind, d.id)); } catch (e2) { /* ignore */ } + } else if (!d._restore) { _backStack.push(origin); var state = { videoDetail: { kind: d.kind, id: d.id, source: d.source || 'library', layer: _backStack.length } };