diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 17a5966644..ea2e44a06f 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -143,6 +143,7 @@ const initialize_data = { resp: { messages: message_range(201, 801), found_newest: false, + anchor: 444, }, }, diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index f98209f418..2bebac24cf 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -340,13 +340,13 @@ exports.start_backfilling_messages = function () { exports.initialize = function () { // get the initial message list function load_more(data) { - // If we received the initially selected message, select it on the client side, - // but not if the user has already selected another one during load. - // - // We fall back to the closest selected id, as the user may have removed - // a stream from the home before already + // If we haven't selected a message in the home view yet, and + // the home view isn't empty, we select the anchor message here. if (home_msg_list.selected_id() === -1 && !home_msg_list.empty()) { - home_msg_list.select_id(page_params.pointer, + // We fall back to the closest selected id, as the user + // may have removed a stream from the home view while we + // were loading data. + home_msg_list.select_id(data.anchor, {then_scroll: true, use_closest: true, target_scroll_offset: page_params.initial_offset}); }