aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/docs
diff options
context:
space:
mode:
authorNtskwK <natsukawa247@outlook.com>2026-03-26 10:22:16 +0800
committerNtskwK <natsukawa247@outlook.com>2026-03-26 10:22:16 +0800
commitd69e408ece77d011d7097a711636f7edf9b0756c (patch)
treea9e702347081bf9798865027b48beb960b2b9145 /packages/docs
parent62d8c7c5c3bc36fbaa1bfba099e3bf04a00c300d (diff)
downloadDropOut-d69e408ece77d011d7097a711636f7edf9b0756c.tar.gz
DropOut-d69e408ece77d011d7097a711636f7edf9b0756c.zip
fix(mermaid): prevent memory leak on unmount
Diffstat (limited to 'packages/docs')
-rw-r--r--packages/docs/app/components/mermaid.tsx7
1 files changed, 6 insertions, 1 deletions
diff --git a/packages/docs/app/components/mermaid.tsx b/packages/docs/app/components/mermaid.tsx
index 3a54a04..fe153ec 100644
--- a/packages/docs/app/components/mermaid.tsx
+++ b/packages/docs/app/components/mermaid.tsx
@@ -13,10 +13,12 @@ export function Mermaid({ chart }: { chart: string }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
+ let current = true;
const id = `mermaid-${Math.random().toString(36).slice(2, 9)}`;
mermaid
.render(id, chart)
.then(({ svg }) => {
+ if (!current) return;
const parser = new DOMParser();
const doc = parser.parseFromString(svg, "image/svg+xml");
const svgEl = doc.querySelector("svg");
@@ -25,8 +27,11 @@ export function Mermaid({ chart }: { chart: string }) {
}
})
.catch(() => {
- ref.current?.replaceChildren();
+ if (current) ref.current?.replaceChildren();
});
+ return () => {
+ current = false;
+ };
}, [chart]);
return (