fix: Add a catch block around a JSON.parse when rendering AI assistant messages (#34671)

Add a catch block around a json.parse.
This commit is contained in:
Ivan Vasilov authored and GitHub committed 2025-04-03 09:44:44 +02:00
1 parent e36f1715b3
commit 86a690b00a
1 file changed
+8 -4
@@ -185,10 +185,14 @@ export const MarkdownPre = ({
const rawContent = children[0].props.children[0]
const propsMatch = rawContent.match(/(?:--|\/\/)\s*props:\s*(\{[^}]+\})/)
const snippetProps: AssistantSnippetProps = useMemo(
() => (propsMatch ? JSON.parse(propsMatch[1]) : {}),
[propsMatch]
)
const snippetProps: AssistantSnippetProps = useMemo(() => {
try {
if (propsMatch) {
return JSON.parse(propsMatch[1])
}
} catch {}
return {}
}, [propsMatch])
const { xAxis, yAxis } = snippetProps
const snippetId = snippetProps.id