warning fix
All checks were successful
checks-impure / test (pull_request) Successful in 26s
checks / test (pull_request) Successful in 3m3s

This commit is contained in:
sara-pervana
2024-01-26 01:19:32 +01:00
parent f3ab6e1b45
commit eaec0feb96

View File

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