From 478d3751255a441bf39057b81f807ffe96a0e97a Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 15 Nov 2024 13:09:40 +0000 Subject: [PATCH] fix: add try-catch block around md renderer fix: update recursive match to block numbered lists --- src/components/markdown/RemarkRenderer.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/markdown/RemarkRenderer.tsx b/src/components/markdown/RemarkRenderer.tsx index 4ebe41d6..8acaf7c6 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -185,7 +185,8 @@ const Container = styled.div<{ largeEmoji: boolean }>` /** * Regex for matching execessive recursion of blockquotes and lists */ -const RE_RECURSIVE = /(^(?:[>*+-][^\S\r\n]*){5})(?:[>*+-][^\S\r\n]*)+(.*$)/gm; +const RE_RECURSIVE = + /(^(?:(?:[>*+-]|\d+\.)[^\S\r\n]*){5})(?:(?:[>*+-]|\d+\.)[^\S\r\n]*)+(.*$)/gm; /** * Regex for matching multi-line blockquotes @@ -247,9 +248,13 @@ export default memo(({ content, disallowBigEmoji }: MarkdownProps) => { const [Content, setContent] = useState(null!); useLayoutEffect(() => { - render - .process(sanitisedContent) - .then((file) => setContent(file.result)); + try { + render + .process(sanitisedContent) + .then((file) => setContent(file.result)); + } catch (err) { + setContent("Message failed to render." as never); + } }, [sanitisedContent]); const largeEmoji = useMemo(