fix(history): an overlay opened while a back() is in flight waits to push its entry
The Plex player's ⋯ → Settings closed the menu (its entry went back) and opened the panel a task later, before that back() had landed. The panel's push was the entry the landing back() took, so the books counted one entry more than the history held, and closing the panel by a click outside it stepped back over the player's own entry: the player closed. A push now waits while a back() of ours is in flight; the popstate that lands the last one reconciles again.
This commit is contained in:
@@ -261,10 +261,14 @@ let listenerInstalled = false;
|
||||
const syncWaiters = new Set<() => void>();
|
||||
|
||||
// Push/pop history entries until their count matches the live overlay count. Runs once per tick.
|
||||
// A push waits while a back() of ours is still in flight: it would land on the entry just pushed and
|
||||
// take it, leaving the books one entry above the history — and the next close then stepped back over
|
||||
// the entry BELOW, the player's own (the Plex player's ⋯ → Settings, then a click outside the panel,
|
||||
// closed the player). The popstate that lands the last back() reconciles again.
|
||||
function reconcileHistory(): void {
|
||||
reconcileScheduled = false;
|
||||
const want = overlayStack.length;
|
||||
while (historyDepth < want) {
|
||||
while (historyDepth < want && pendingProgrammatic === 0) {
|
||||
historyDepth++;
|
||||
window.history.pushState({ ...window.history.state, _ov: nextOverlayToken() }, "");
|
||||
}
|
||||
@@ -294,6 +298,8 @@ function ensureOverlayListener(): void {
|
||||
window.addEventListener("popstate", () => {
|
||||
if (pendingProgrammatic > 0) {
|
||||
pendingProgrammatic--; // our own back(): consume and ignore
|
||||
// The last one landed: an overlay that opened while it was in flight still owes its entry.
|
||||
if (pendingProgrammatic === 0 && historyDepth < overlayStack.length) scheduleReconcile();
|
||||
return;
|
||||
}
|
||||
// Genuine user Back: the browser already dropped one overlay entry, so close the topmost
|
||||
|
||||
Reference in New Issue
Block a user