From 2011e0df760cea52c31914e7b77d9b4e38e9ee74 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 2 Aug 2024 05:41:45 +0000 Subject: [PATCH] inbox_ui: Fix row_focus not synced with inbox rows. Have one inbox row and focus on it. Mark the message as read in another tab. Press `r` in the first tab will return an error as the row_focus didn't change but there is no present. So, we fix it by updating the row_focus if it can get out of bounds when updating inbox view. --- web/src/inbox_ui.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts index f66141a5bc..b442681270 100644 --- a/web/src/inbox_ui.ts +++ b/web/src/inbox_ui.ts @@ -1327,9 +1327,17 @@ export function update(): void { const has_visible_unreads = has_dms_post_filter || has_topics_post_filter; show_empty_inbox_text(has_visible_unreads); + // We want to avoid weird jumps when user is interacting with Inbox + // and we are updating the view. So, we only reset current focus if + // the update was triggered by user. This can mean `row_focus` can + // be out of bounds, so we need to fix that. if (update_triggered_by_user) { setTimeout(revive_current_focus, 0); update_triggered_by_user = false; + } else { + if (row_focus >= get_all_rows().length) { + revive_current_focus(); + } } }