From 7fa01da30ef998ab36d1881755f2cdce08bd405b Mon Sep 17 00:00:00 2001 From: Daniel Avila Date: Thu, 7 Sep 2023 07:00:53 -0400 Subject: [PATCH] refactor(Markdown.tsx): add isEdited as a condition whether or not to render html as well as perform expensive validation --- client/src/components/Messages/Content/Markdown.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/src/components/Messages/Content/Markdown.tsx b/client/src/components/Messages/Content/Markdown.tsx index 367e52f1a9..11061a906a 100644 --- a/client/src/components/Messages/Content/Markdown.tsx +++ b/client/src/components/Messages/Content/Markdown.tsx @@ -45,9 +45,10 @@ const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => const isSubmitting = useRecoilValue(store.isSubmitting); const latestMessage = useRecoilValue(store.latestMessage); const isInitializing = content === ''; - const isLatestMessage = message?.messageId === latestMessage?.messageId; + + const { isEdited, messageId } = message ?? {}; + const isLatestMessage = messageId === latestMessage?.messageId; const currentContent = content?.replace('z-index: 1;', '') ?? ''; - const isValidIFrame = validateIframe(currentContent); useEffect(() => { let timer1: NodeJS.Timeout, timer2: NodeJS.Timeout; @@ -88,7 +89,12 @@ const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => [rehypeRaw], ]; - if ((!isInitializing || !isLatestMessage) && !isValidIFrame) { + let isValidIframe: string | boolean | null = false; + if (!isEdited) { + isValidIframe = validateIframe(currentContent); + } + + if (isEdited || ((!isInitializing || !isLatestMessage) && !isValidIframe)) { rehypePlugins.pop(); }