inbox_ui: Fix scroll jump after initial render.

It is possible for us to scroll user back to top of view if they
scroll before the render is complete and we haven't called
`revive_current_focus` yet.

This fixes it by wrapping the render and revive logic in a single
animation frame so that any scroll requests are delayed until we
have completed both of them.
This commit is contained in:
Aman Agrawal
2025-08-05 18:04:18 +05:30
committed by Tim Abbott
parent 9c0777ad26
commit 067ecbbbfe

View File

@@ -1168,6 +1168,9 @@ export function complete_rerender(): void {
} }
load_data_from_ls(); load_data_from_ls();
// To avoid user scrolling before we have completed the rendering,
// Wrap the rendering and position restoration in a requestAnimationFrame.
requestAnimationFrame(() => {
let first_filter: IteratorResult<string>; let first_filter: IteratorResult<string>;
if (inbox_util.is_channel_view()) { if (inbox_util.is_channel_view()) {
const channel_id = inbox_util.get_channel_id(); const channel_id = inbox_util.get_channel_id();
@@ -1221,10 +1224,8 @@ export function complete_rerender(): void {
window.scrollTo(0, last_scroll_offset); window.scrollTo(0, last_scroll_offset);
} }
setTimeout(() => {
revive_current_focus(); revive_current_focus();
is_waiting_for_revive_current_focus = false; is_waiting_for_revive_current_focus = false;
}, 0);
filters_dropdown_widget = new dropdown_widget.DropdownWidget({ filters_dropdown_widget = new dropdown_widget.DropdownWidget({
...views_util.COMMON_DROPDOWN_WIDGET_PARAMS, ...views_util.COMMON_DROPDOWN_WIDGET_PARAMS,
@@ -1235,6 +1236,7 @@ export function complete_rerender(): void {
get_options: inbox_view_dropdown_options, get_options: inbox_view_dropdown_options,
}); });
filters_dropdown_widget.setup(); filters_dropdown_widget.setup();
});
} }
export function search_and_update(): void { export function search_and_update(): void {