Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

browser_history: Delay user_settings.default_view evaluation.

Anders Kaseorg4650b789ce3a
diff --git a/web/src/browser_history.ts b/web/src/browser_history.ts
index 62422c2bcf9..46a468f4482 100644
--- a/web/src/browser_history.ts
+++ b/web/src/browser_history.ts
@@ -10,7 +10,7 @@ export const state: {
hash_before_overlay: string | null;
old_hash: string;
changing_hash: boolean;
- spectator_old_hash: string;
+ spectator_old_hash: string | null;
} = {
is_internal_change: false,
hash_before_overlay: null,
@@ -22,7 +22,7 @@ export const state: {
// hashes are changed without calling `hashchanged` in many ways.
spectator_old_hash: hash_util.is_spectator_compatible(window.location.hash)
? window.location.hash
- : `#${user_settings.default_view}`,
+ : null,
};
export function clear_for_testing(): void {
@@ -100,5 +100,5 @@ export function update_hash_internally_if_required(hash: string): void {
}
export function return_to_web_public_hash(): void {
- window.location.hash = state.spectator_old_hash;
+ window.location.hash = state.spectator_old_hash ?? `#${user_settings.default_view}`;
}
diff --git a/web/tests/browser_history.test.js b/web/tests/browser_history.test.js
index 2a950025b2a..19236671024 100644
--- a/web/tests/browser_history.test.js
+++ b/web/tests/browser_history.test.js
@@ -8,13 +8,13 @@ const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {user_settings} = require("./lib/zpage_params");
-user_settings.default_view = "recent";
window.location.hash = "#bogus";
const browser_history = zrequire("browser_history");
function test(label, f) {
run_test(label, (...args) => {
+ user_settings.default_view = "recent";
window.location.hash = "#bogus";
browser_history.clear_for_testing();
f(...args);