File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,7 @@ pub fn route_handler(state: SharedState) -> Router<Arc<UiState>> {
206206 get ( settings:: get_settings_followers) ,
207207 )
208208 . route ( "/ui/settings/unfollow" , post ( settings:: post_unfollow) )
209+ . route ( "/ui/timeline/prime" , get ( timeline_prime) )
209210 // .route("/a/", put(account_new))
210211 // .route("/t/", put(token_new))
211212 // .route("/m/", put(metric_new).get(metric_find))
@@ -219,3 +220,15 @@ pub fn route_handler(state: SharedState) -> Router<Arc<UiState>> {
219220async fn root ( ) -> Redirect {
220221 Redirect :: permanent ( "/ui" )
221222}
223+
224+ /// Returns empty timeline-posts div for priming alpine-ajax.
225+ ///
226+ /// Workaround: The first alpine-ajax request on a page causes the browser to
227+ /// scroll to the top. By triggering a dummy ajax request on page load (when
228+ /// we're already at the top), the first real infinite scroll request won't
229+ /// cause the unwanted scroll jump.
230+ async fn timeline_prime ( ) -> Maud {
231+ Maud ( maud:: html! {
232+ div id="timeline-posts" x-merge="append" { }
233+ } )
234+ }
Original file line number Diff line number Diff line change @@ -548,6 +548,8 @@ impl UiState {
548548
549549 Ok ( html ! {
550550 div . "o-mainBarTimeline" "x-data" ="{}" {
551+ // Workaround: first alpine-ajax request scrolls to top; prime it on load
552+ div style="display:none" x-init="$ajax('/ui/timeline/prime', { targets: ['timeline-posts'] })" { }
551553 div . "o-mainBarTimeline__tabs" {
552554 a . "o-mainBarTimeline__back" onclick="history.back()" { "<" }
553555
You can’t perform that action at this time.
0 commit comments