diff --git a/frontend/src/app.js b/frontend/src/app.js index 958b3ad2a..1b08e1663 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -113,12 +113,12 @@ Vue.use(VueFilters); Vue.use(Components); Vue.use(Dialogs); -window.popStateDetected = false; +window.backwardsNavigationDetected = false; window.addEventListener("popstate", (event) => { - window.popStateDetected = true; - // give components time to react to popStateDetected in `created` or '$route'-watcher + window.backwardsNavigationDetected = true; + // give components time to react to backwardsNavigationDetected in `created` or '$route'-watcher setTimeout(() => { - window.popStateDetected = false; + window.backwardsNavigationDetected = false; }); }); diff --git a/frontend/src/pages/albums.vue b/frontend/src/pages/albums.vue index 073698e1c..a906cd380 100644 --- a/frontend/src/pages/albums.vue +++ b/frontend/src/pages/albums.vue @@ -301,9 +301,6 @@ export default { } }, created() { - if (!window.popStateDetected) { - this.setOffset(0); - } this.search(); this.subscriptions.push(Event.subscribe("albums", (ev, data) => this.onUpdate(ev, data))); @@ -568,6 +565,15 @@ export default { return params; }, search() { + /** + * re-creating the last scroll-position should only ever happen when using + * back-navigation. We therefore reset the remembered scroll-position + * in any other scenario + */ + if (!window.backwardsNavigationDetected) { + this.setOffset(0); + } + this.scrollDisabled = true; // Don't query the same data more than once diff --git a/frontend/src/pages/labels.vue b/frontend/src/pages/labels.vue index 7284e69dc..9a73ccfe7 100644 --- a/frontend/src/pages/labels.vue +++ b/frontend/src/pages/labels.vue @@ -204,9 +204,6 @@ export default { }, }, created() { - if (!window.popStateDetected) { - this.setOffset(0); - } this.search(); this.subscriptions.push(Event.subscribe("labels", (ev, data) => this.onUpdate(ev, data))); @@ -506,6 +503,15 @@ export default { this.loadMore(); }, search() { + /** + * re-creating the last scroll-position should only ever happen when using + * back-navigation. We therefore reset the remembered scroll-position + * in any other scenario + */ + if (!window.backwardsNavigationDetected) { + this.setOffset(0); + } + this.scrollDisabled = true; // Don't query the same data more than once diff --git a/frontend/src/pages/people/subjects.vue b/frontend/src/pages/people/subjects.vue index eb304aee7..202ca604a 100644 --- a/frontend/src/pages/people/subjects.vue +++ b/frontend/src/pages/people/subjects.vue @@ -249,9 +249,6 @@ export default { } }, created() { - if (!window.popStateDetected) { - this.setOffset(0); - } this.search(); this.subscriptions.push(Event.subscribe("subjects", (ev, data) => this.onUpdate(ev, data))); @@ -616,6 +613,15 @@ export default { this.loadMore(); }, search() { + /** + * re-creating the last scroll-position should only ever happen when using + * back-navigation. We therefore reset the remembered scroll-position + * in any other scenario + */ + if (!window.backwardsNavigationDetected) { + this.setOffset(0); + } + this.scrollDisabled = true; // Don't query the same data more than once diff --git a/frontend/src/pages/photos.vue b/frontend/src/pages/photos.vue index 6a4a2a357..b79dd3bc1 100644 --- a/frontend/src/pages/photos.vue +++ b/frontend/src/pages/photos.vue @@ -444,7 +444,12 @@ export default { return; } - if (!window.popStateDetected) { + /** + * re-creating the last scroll-position should only ever happen when using + * back-navigation. We therefore reset the remembered scroll-position + * in any other scenario + */ + if (!window.backwardsNavigationDetected) { window.localStorage.removeItem("last_opened_photo"); this.setOffset(0); } diff --git a/frontend/src/share/albums.vue b/frontend/src/share/albums.vue index 2a2d92477..cc7601d97 100644 --- a/frontend/src/share/albums.vue +++ b/frontend/src/share/albums.vue @@ -190,9 +190,6 @@ export default { } }, created() { - if (!window.popStateDetected) { - this.setOffset(0); - } const token = this.$route.params.token; if (this.$session.hasToken(token)) { @@ -385,6 +382,15 @@ export default { return params; }, search() { + /** + * re-creating the last scroll-position should only ever happen when using + * back-navigation. We therefore reset the remembered scroll-position + * in any other scenario + */ + if (!window.backwardsNavigationDetected) { + this.setOffset(0); + } + this.scrollDisabled = true; // Don't query the same data more than once