From 3a3628e9b0b41d632f2486be093d7f880dd28a65 Mon Sep 17 00:00:00 2001 From: Joe <33972521+hnb-ku@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:39:30 +0800 Subject: [PATCH] UX: Fixes navigation 1px jitter (#17467) Context: https://meta.discourse.org/t/pixel-jump-whenever-page-refreshes-mobile-desktop/231053 We currently add 1 extra pixel when we try to restore the last scroll position on a few routes. This is causing a bit of jumpiness, as described in the linked topic above. Notice how the content shifts by 1px while stuff loads. I believe this 1px that we add is an artifact from the days when we used to set the header to `fixed` but I'm not sure. Either way, the header now uses `position: sticky;` so we shouldn't need that 1px adjustment. This PR introduced no visual changes except that it fixes the jitter mentioned above. --- .../javascripts/discourse/app/components/bookmark-list.js | 2 +- .../discourse/app/components/discovery-topics-list.js | 2 +- app/assets/javascripts/discourse/app/components/topic-list.js | 2 +- app/assets/javascripts/discourse/app/components/user-stream.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/bookmark-list.js b/app/assets/javascripts/discourse/app/components/bookmark-list.js index 03f2b863629..594bf4ff110 100644 --- a/app/assets/javascripts/discourse/app/components/bookmark-list.js +++ b/app/assets/javascripts/discourse/app/components/bookmark-list.js @@ -31,7 +31,7 @@ export default Component.extend(Scrolling, { if (scrollTo >= 0) { schedule("afterRender", () => { if (this.element && !this.isDestroying && !this.isDestroyed) { - next(() => window.scrollTo(0, scrollTo + 1)); + next(() => window.scrollTo(0, scrollTo)); } }); } diff --git a/app/assets/javascripts/discourse/app/components/discovery-topics-list.js b/app/assets/javascripts/discourse/app/components/discovery-topics-list.js index 2b304caa1d9..4821ade3736 100644 --- a/app/assets/javascripts/discourse/app/components/discovery-topics-list.js +++ b/app/assets/javascripts/discourse/app/components/discovery-topics-list.js @@ -17,7 +17,7 @@ export default Component.extend(UrlRefresh, LoadMore, { if (scrollTo >= 0) { schedule("afterRender", () => { if (this.element && !this.isDestroying && !this.isDestroyed) { - next(() => window.scrollTo(0, scrollTo + 1)); + next(() => window.scrollTo(0, scrollTo)); } }); } else { diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js index 360425fae55..e06f9c18e41 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list.js +++ b/app/assets/javascripts/discourse/app/components/topic-list.js @@ -78,7 +78,7 @@ export default Component.extend(LoadMore, { if (scrollTo >= 0) { schedule("afterRender", () => { if (this.element && !this.isDestroying && !this.isDestroyed) { - next(() => window.scrollTo(0, scrollTo + 1)); + next(() => window.scrollTo(0, scrollTo)); } }); } diff --git a/app/assets/javascripts/discourse/app/components/user-stream.js b/app/assets/javascripts/discourse/app/components/user-stream.js index 6262ba75fe6..53b636831d5 100644 --- a/app/assets/javascripts/discourse/app/components/user-stream.js +++ b/app/assets/javascripts/discourse/app/components/user-stream.js @@ -77,7 +77,7 @@ export default Component.extend(LoadMore, { if (scrollTo >= 0) { schedule("afterRender", () => { if (this.element && !this.isDestroying && !this.isDestroyed) { - next(() => window.scrollTo(0, scrollTo + 1)); + next(() => window.scrollTo(0, scrollTo)); } }); }