From 527d4672f85adfb2d6cbb93acf9a4e580e30984e Mon Sep 17 00:00:00 2001 From: evykassirer Date: Sun, 3 Nov 2024 16:16:22 -0800 Subject: [PATCH] settings_components: Fix types in save_discard_stream_settings_widget_status_handler. This had been getting undefined `sub` already, in the modal to create a new channel, but managed to not cause errors because `properties_elements` was empty and `button_state` didn't equal `"unsaved"`, leaving areas that treated `sub` as defined not accessible. This commit fixes the type and handles the `undefined` case more directly. --- web/src/settings_components.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 70c5b099bf..e44a7b354a 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -1203,14 +1203,17 @@ export function save_discard_realm_settings_widget_status_handler($subsection: J export function save_discard_stream_settings_widget_status_handler( $subsection: JQuery, - sub: StreamSubscription, + sub: StreamSubscription | undefined, ): void { $subsection.find(".subsection-failed-status p").hide(); $subsection.find(".save-button").show(); const properties_elements = get_subsection_property_elements($subsection); - const show_change_process_button = properties_elements.some((elem) => - check_stream_settings_property_changed(elem, sub), - ); + let show_change_process_button = false; + if (sub !== undefined) { + show_change_process_button = properties_elements.some((elem) => + check_stream_settings_property_changed(elem, sub), + ); + } const $save_btn_controls = $subsection.find(".subsection-header .save-button-controls"); const button_state = show_change_process_button ? "unsaved" : "discarded"; @@ -1222,6 +1225,7 @@ export function save_discard_stream_settings_widget_status_handler( // making it private unless they subscribe. if ( button_state === "unsaved" && + sub && !sub.invite_only && !sub.subscribed && switching_to_private(properties_elements)