Added a lot of fixes #73

Merged
Ghost merged 12 commits from more-fixes into main 2024-01-26 00:25:58 +00:00
Showing only changes of commit eaec0feb96 - Show all commits

View File

@@ -55,9 +55,13 @@ const SequenceDiagram = () => {
const dataDependency = JSON.stringify(hasData ? eventMessagesData?.data : "");
useEffect(() => {
const currentMermaidRef = mermaidRef?.current;
if (!loadingEventMessages && hasData) {
// check for the absence of this attribute to render the diagram
if (!mermaidRef.current.getAttribute("data-processed")) {
if (
currentMermaidRef &&
!currentMermaidRef.getAttribute("data-processed")
) {
mermaid.initialize({
startOnLoad: false,
securityLevel: "loose",
@@ -67,19 +71,16 @@ const SequenceDiagram = () => {
},
});
}
}
if (mermaidRef.current) {
mermaidRef.current.innerHTML = mermaidString;
mermaid.init(undefined, mermaidRef.current);
if (currentMermaidRef) {
currentMermaidRef.innerHTML = mermaidString;
mermaid.init(undefined, currentMermaidRef);
}
}
return () => {
if (mermaidRef.current) {
// By removing the 'data-processed' attribute, we ensure Mermaid will process the diagram again
mermaidRef.current.removeAttribute("data-processed");
// Reset the innerHTML to clear the diagram
mermaidRef.current.innerHTML = "";
if (currentMermaidRef) {
currentMermaidRef.removeAttribute("data-processed");
currentMermaidRef.innerHTML = "";
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps