diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index 82c50cd4e4..370a86ac24 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -48,8 +48,10 @@ function do_narrow(description, filter_function) { // is temporarily selected select_message_by_id(selected_message_id, {then_scroll: false}); selected_message_class = "narrowed_selected_message"; - select_message_by_id(target_id, {then_scroll: true}); - scroll_to_selected(); + if (select_message_by_id(target_id, {then_scroll: true})) { + // Can only scroll if the message exists + scroll_to_selected(); + } } // This is the message we're about to select, within the narrowed view. diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 34de1b85f8..22678fb23b 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -121,7 +121,8 @@ function recenter_view(message) { } function scroll_to_selected() { - recenter_view(selected_message); + if (selected_message && (selected_message.length !== 0)) + recenter_view(selected_message); } function get_huddle_recipient(message) { @@ -749,6 +750,8 @@ function at_bottom_of_viewport() { function keep_pointer_in_view() { var candidate; var next_message = rows.get(selected_message_id); + if (next_message.length === 0) + return; if (above_view_threshold(next_message) && (!at_top_of_viewport())) { while (above_view_threshold(next_message)) {