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
This commit is contained in:
alunturner 2023-06-21 09:22:06 +01:00 committed by GitHub
parent a4cf2af187
commit ad8543eb58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -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 // we need to import the types for TS, but do not import the sendMessage
// function to avoid importing from "@matrix-org/matrix-wysiwyg" // function to avoid importing from "@matrix-org/matrix-wysiwyg"
import { SendMessageParams } from "./utils/message"; import { SendMessageParams } from "./utils/message";
import { retry } from "../../../../utils/promise";
const SendComposer = lazy(() => import("./SendWysiwygComposer")); // Due to issues such as https://github.com/vector-im/element-web/issues/25277, we add retry
const EditComposer = lazy(() => import("./EditWysiwygComposer")); // 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 ( export const dynamicImportSendMessage = async (
message: string, message: string,
isHTML: boolean, isHTML: boolean,
params: SendMessageParams, params: SendMessageParams,
): Promise<ISendEventResponse | undefined> => { ): Promise<ISendEventResponse | undefined> => {
const { sendMessage } = await import("./utils/message"); const { sendMessage } = await retry(() => import("./utils/message"), RETRY_COUNT);
return sendMessage(message, isHTML, params); return sendMessage(message, isHTML, params);
}; };
@ -38,7 +42,7 @@ export const dynamicImportConversionFunctions = async (): Promise<{
richToPlain(rich: string): Promise<string>; richToPlain(rich: string): Promise<string>;
plainToRich(plain: 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 }; return { richToPlain, plainToRich };
}; };

View file

@ -40,7 +40,7 @@ const Content = forwardRef<HTMLElement, ContentProps>(function Content(
return null; return null;
}); });
interface SendWysiwygComposerProps { export interface SendWysiwygComposerProps {
initialContent?: string; initialContent?: string;
isRichTextEnabled: boolean; isRichTextEnabled: boolean;
placeholder?: string; placeholder?: string;