From 4ae622bdd3389ebfbab59417c7d2922ff7807fcc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 9 Oct 2020 16:58:53 +0200 Subject: [PATCH] make pushUrl silent again --- src/ui/web/dom/History.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ui/web/dom/History.js b/src/ui/web/dom/History.js index 08bd6ed0..797f108f 100644 --- a/src/ui/web/dom/History.js +++ b/src/ui/web/dom/History.js @@ -20,9 +20,14 @@ export class History extends BaseObservableValue { constructor() { super(); this._boundOnHashChange = null; + this._expectSetEcho = false; } _onHashChange() { + if (this._expectSetEcho) { + this._expectSetEcho = false; + return; + } this.emit(this.get()); } @@ -37,7 +42,19 @@ export class History extends BaseObservableValue { } pushUrl(url) { - document.location.hash = this.urlAsPath(url); + const hash = this.urlAsPath(url); + // important to check before we expect an echo + // as setting the hash to it's current value doesn't + // trigger onhashchange + if (hash === document.location.hash) { + return; + } + // this operation is silent, + // so avoid emitting on echo hashchange event + if (this._boundOnHashChange) { + this._expectSetEcho = true; + } + document.location.hash = hash; } urlAsPath(url) {