Skip to content
Snippets Groups Projects
Verified Commit fcbebd37 authored by Dorian Koch's avatar Dorian Koch
Browse files

Improve StylizedText rendering performance by avoiding markdown

parent e00b7c94
No related branches found
No related tags found
No related merge requests found
Pipeline #6307 passed
......@@ -25,6 +25,16 @@ export function StylizedText({
str = str.replaceAll(/<strong>(.*?)<\/strong>/gs, "**$1**");
str = str.replaceAll(/<p>(.*?)<\/p>/gs, "$1\n\n");
str = str.replaceAll(/<!--(.*?)-->/gs, "");
// first test if there is any markdown in the string at all
// markdown rendering is expensive (~1ms per Component) so we want to avoid it if possible
// this is a very simple test and will not catch all cases, but it will never give a false positive
if (!str.match(/[*#[\]\d(`>-]/)) {
if (mapParagraphToSpan)
return str.split("\n\n").map((line, index) => <span key={index}>{line}</span>);
return str.split("\n\n").map((line, index) => <p key={index}>{line}</p>);
}
return (
<Suspense fallback={str}>
<LazyMarkdown
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment