browser_history: Delay user_settings.default_view evaluation.

Commit 61f7ede43c (#25759) introduced a
bug: browser_history tried to access user_settings.default_view at top
level as soon as it was imported, before
user_settings.initialize_user_settings has been called, so
browser_history.state.spectator_old_hash was always initialized to
"#undefined".

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-09-11 13:50:09 -07:00 committed by Tim Abbott
parent 6988622fe8
commit 4650b789ce
2 changed files with 4 additions and 4 deletions

View File

@ -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}`;
}

View File

@ -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);