From 59a45d3521dc7fda8c1b4ec00c47dcf74b40ded5 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Mon, 15 Mar 2021 14:01:19 +0000 Subject: [PATCH] hashchange: Render default view on empty hash. Instead of changing the hash to the default_view hash, we render the default_view directly in case of recent topics and all messages. This also fixes the bug that user is unable to go back in browser window history. --- static/js/hashchange.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 23338b09e0..6c6ae28adc 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -95,7 +95,21 @@ function activate_home_tab() { } export function show_default_view() { - window.location.hash = page_params.default_view; + // We only allow all_messages and recent_topics + // to be rendered without a hash. + if (page_params.default_view === "recent_topics") { + recent_topics.show(); + } else if (page_params.default_view === "all_messages") { + activate_home_tab(); + } else { + // NOTE: Setting a hash which is not rendered on + // empty hash (like a stream narrow) will + // introduce a bug that user will not be able to + // go back in broswer history. See + // https://chat.zulip.org/#narrow/stream/9-issues/topic/Browser.20back.20button.20on.20RT + // for detailed description of the issue. + window.location.hash = page_params.default_view; + } } // Returns true if this function performed a narrow @@ -112,8 +126,11 @@ function do_hashchange_normal(from_reload) { ui_util.change_tab_to("#message_feed_container"); const operators = hash_util.parse_narrow(hash); if (operators === undefined) { - // If the narrow URL didn't parse, clear - // window.location.hash and send them to the home tab + // If the narrow URL didn't parse, + // send them to default_view. + // We cannot clear hash here since + // it will block user from going back + // in browser history. show_default_view(); return false; }