Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Increase RTE resilience (#11111)
Browse files Browse the repository at this point in the history
* add retry logic to the dynamic import for the composers

* add retry to the conversion function too

* add retry to final function

* add comment
  • Loading branch information
alunturner committed Jun 21, 2023
1 parent a4cf2af commit ad8543e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISendEventResponse | undefined> => {
const { sendMessage } = await import("./utils/message");
const { sendMessage } = await retry(() => import("./utils/message"), RETRY_COUNT);

return sendMessage(message, isHTML, params);
};
Expand All @@ -38,7 +42,7 @@ export const dynamicImportConversionFunctions = async (): Promise<{
richToPlain(rich: string): Promise<string>;
plainToRich(plain: string): Promise<string>;
}> => {
const { richToPlain, plainToRich } = await import("@matrix-org/matrix-wysiwyg");
const { richToPlain, plainToRich } = await retry(() => import("@matrix-org/matrix-wysiwyg"), RETRY_COUNT);

return { richToPlain, plainToRich };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Content = forwardRef<HTMLElement, ContentProps>(function Content(
return null;
});

interface SendWysiwygComposerProps {
export interface SendWysiwygComposerProps {
initialContent?: string;
isRichTextEnabled: boolean;
placeholder?: string;
Expand Down

0 comments on commit ad8543e

Please sign in to comment.