From 377def4a3373e1f59377c1d358644aac0c086f14 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 6 Feb 2024 18:12:09 +0100 Subject: [PATCH] Fix crash when toggling chat button plugins without restart --- src/api/ChatButtons.tsx | 15 +++++++-------- src/plugins/invisibleChat.desktop/index.tsx | 2 +- src/plugins/previewMessage/index.tsx | 4 +--- src/plugins/sendTimestamps/index.tsx | 2 +- src/plugins/silentMessageToggle/index.tsx | 2 +- src/plugins/silentTyping/index.tsx | 2 +- src/plugins/translate/TranslateIcon.tsx | 2 +- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/api/ChatButtons.tsx b/src/api/ChatButtons.tsx index c2194dd70..fcb76fffc 100644 --- a/src/api/ChatButtons.tsx +++ b/src/api/ChatButtons.tsx @@ -74,7 +74,7 @@ export interface ChatBarProps { }; } -export type ChatBarButton = (props: ChatBarProps, isMainChat: boolean) => ReactNode; +export type ChatBarButton = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null; const buttonFactories = new Map(); const logger = new Logger("ChatButtons"); @@ -82,13 +82,12 @@ const logger = new Logger("ChatButtons"); export function _injectButtons(buttons: ReactNode[], props: ChatBarProps) { if (props.disabled) return; - for (const [key, makeButton] of buttonFactories) { - try { - const res = makeButton(props, props.type.analyticsName === "normal"); - if (res) buttons.push(res); - } catch (e) { - logger.error(`Failed to render button ${key}`, e); - } + for (const [key, Button] of buttonFactories) { + buttons.push( + logger.error(`Failed to render ${key}`, e.error)}> +