From ad8543eb586f0fca5ee684d8ac9cb1acfc02b0ef Mon Sep 17 00:00:00 2001 From: alunturner <56027671+alunturner@users.noreply.github.com> Date: Wed, 21 Jun 2023 09:22:06 +0100 Subject: [PATCH] Increase RTE resilience (#11111) * add retry logic to the dynamic import for the composers * add retry to the conversion function too * add retry to final function * add comment --- .../DynamicImportWysiwygComposer.tsx | 12 ++++++++---- .../rooms/wysiwyg_composer/SendWysiwygComposer.tsx | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/wysiwyg_composer/DynamicImportWysiwygComposer.tsx b/src/components/views/rooms/wysiwyg_composer/DynamicImportWysiwygComposer.tsx index afe8396bbd..a7d79b617b 100644 --- a/src/components/views/rooms/wysiwyg_composer/DynamicImportWysiwygComposer.tsx +++ b/src/components/views/rooms/wysiwyg_composer/DynamicImportWysiwygComposer.tsx @@ -20,16 +20,20 @@ import { ISendEventResponse } from "matrix-js-sdk/src/@types/requests"; // we need to import the types for TS, but do not import the sendMessage // function to avoid importing from "@matrix-org/matrix-wysiwyg" import { SendMessageParams } from "./utils/message"; +import { retry } from "../../../../utils/promise"; -const SendComposer = lazy(() => import("./SendWysiwygComposer")); -const EditComposer = lazy(() => import("./EditWysiwygComposer")); +// Due to issues such as https://github.com/vector-im/element-web/issues/25277, we add retry +// attempts to all of the dynamic imports in this file +const RETRY_COUNT = 3; +const SendComposer = lazy(() => retry(() => import("./SendWysiwygComposer"), RETRY_COUNT)); +const EditComposer = lazy(() => retry(() => import("./EditWysiwygComposer"), RETRY_COUNT)); export const dynamicImportSendMessage = async ( message: string, isHTML: boolean, params: SendMessageParams, ): Promise => { - const { sendMessage } = await import("./utils/message"); + const { sendMessage } = await retry(() => import("./utils/message"), RETRY_COUNT); return sendMessage(message, isHTML, params); }; @@ -38,7 +42,7 @@ export const dynamicImportConversionFunctions = async (): Promise<{ richToPlain(rich: string): Promise; plainToRich(plain: string): Promise; }> => { - const { richToPlain, plainToRich } = await import("@matrix-org/matrix-wysiwyg"); + const { richToPlain, plainToRich } = await retry(() => import("@matrix-org/matrix-wysiwyg"), RETRY_COUNT); return { richToPlain, plainToRich }; }; diff --git a/src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.tsx b/src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.tsx index 34307ce4ab..d5cc08e4f0 100644 --- a/src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.tsx +++ b/src/components/views/rooms/wysiwyg_composer/SendWysiwygComposer.tsx @@ -40,7 +40,7 @@ const Content = forwardRef(function Content( return null; }); -interface SendWysiwygComposerProps { +export interface SendWysiwygComposerProps { initialContent?: string; isRichTextEnabled: boolean; placeholder?: string;