From b7c4d788ed60a0852ac7ab243b9e66fdac891a76 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 7 Sep 2017 12:06:43 +0200 Subject: [PATCH] Prevent a temporary position from being added to the history while a destination is scrolled into view Since e.g. zooming can occur when navigating to a new destionation, ensure that a resulting 'updateviewarea' event doesn't trigger adding of a *temporary* position to the browser history at a bad time. --- web/pdf_history.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/pdf_history.js b/web/pdf_history.js index 157013af8..5c834f386 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -189,6 +189,17 @@ class PDFHistory { hash, page: pageNumber, }, forceReplace); + + if (!this._popStateInProgress) { + // Prevent the browser history from updating while the new destination is + // being scrolled into view, to avoid potentially inconsistent state. + this._popStateInProgress = true; + // We defer the resetting of `this._popStateInProgress`, to account for + // e.g. zooming occuring when the new destination is being navigated to. + Promise.resolve().then(() => { + this._popStateInProgress = false; + }); + } } /**