Skip to content

Commit b91ba10

Browse files
committed
fix: inifinte scrolling with a priming workaround
1 parent af676c3 commit b91ba10

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

crates/rostra-web-ui/src/routes.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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>> {
219220
async 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+
}

crates/rostra-web-ui/src/routes/timeline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)