fix(plex): a Restart does not replay on a reload or a Forward onto the player

fromStart rode in history.state._sub, so reloading the player entry restarted
the item from 0 again and the progress checkpoint overwrote its resume point.
A sub-view config can now say what the history entry keeps of a view.
This commit is contained in:
2026-09-27 14:03:48 +02:00
parent de62035889
commit 383c85231a
4 changed files with 57 additions and 2 deletions
+6 -2
View File
@@ -106,6 +106,9 @@ export interface SubviewUrl<T> {
encode: (view: T) => string | null;
/** Parse a param value back to a sub-view, or null if it isn't a valid one. */
decode: (raw: string) => T | null;
/** What the history ENTRY keeps of a view, when that is less than the view opens with: a one-shot
* flag (the Plex player's `fromStart`) must not replay on a reload or a Forward onto the entry. */
entry?: (view: T) => T;
}
export function useHistorySubview<T>(
@@ -152,19 +155,20 @@ export function useHistorySubview<T>(
const open = useCallback(
(next: T, opts?: { replace?: boolean }) => {
setView(next);
const kept = url?.entry ? url.entry(next) : next;
const href = url ? urlWithParams({ [url.key]: url.encode(next) }) : "";
if (opts?.replace) {
// Same ENTRY, so it keeps its sfScroll id: PageScroller keys offsets per (entry, view), and
// the view key has changed, so the sub-view still opens at the top without minting an id
// that would orphan the one this entry already carries.
window.history.replaceState({ ...window.history.state, _sub: next }, "", href);
window.history.replaceState({ ...window.history.state, _sub: kept }, "", href);
notifyNav();
return;
}
// A fresh sfScroll so the opened sub-view is its own scroll entry (starts at the top, and Back
// restores the view we came from) — then notify PageScroller, which this push doesn't re-render.
window.history.pushState(
{ ...rememberNavPosition(), _sub: next, sfScroll: nextNavId() },
{ ...rememberNavPosition(), _sub: kept, sfScroll: nextNavId() },
"",
href,
);