Skip to content

Commit efd6f9d

Browse files
mlopezFCjavier-godoy
authored andcommitted
fix: improve error handling in mermaid support
1 parent 5a20c50 commit efd6f9d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/main/resources/META-INF/resources/frontend/markdown-viewer.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,32 @@ const Code = ({ inline, children = [], className, ...props }) => {
4747
: children[0] || "";
4848

4949
useEffect(() => {
50-
if (container && isMermaid && demoid.current && code) {
50+
let isMounted = true;
51+
if (container && isMermaid && code) {
5152
mermaid
5253
.render(demoid.current, code)
5354
.then(({ svg, bindFunctions }) => {
54-
container.innerHTML = svg;
55-
if (bindFunctions) {
56-
bindFunctions(container);
55+
if (isMounted) {
56+
container.innerHTML = svg;
57+
if (bindFunctions) {
58+
bindFunctions(container);
59+
}
5760
}
5861
})
5962
.catch((error) => {
63+
if (isMounted) {
64+
container.innerHTML = "Mermaid render error";
65+
}
6066
console.log("error:", error);
6167
});
6268
}
69+
70+
return () => {
71+
isMounted = false;
72+
if (container) {
73+
container.innerHTML = "";
74+
}
75+
};
6376
}, [container, isMermaid, code, demoid]);
6477

6578
const refElement = useCallback((node) => {

0 commit comments

Comments
 (0)