diff --git a/apps/web/src/pages/PluginGraphPage.tsx b/apps/web/src/pages/PluginGraphPage.tsx index 332518f..ffa9a7d 100644 --- a/apps/web/src/pages/PluginGraphPage.tsx +++ b/apps/web/src/pages/PluginGraphPage.tsx @@ -376,15 +376,22 @@ export function PluginGraphPage() { } }, [canvasSize, selectedCenter, hoverState, token]); - // ── Animation loop ── + // ── On-demand redraw: data changes + resize ── + // 数据变更时触发单次重绘 useEffect(() => { - const animate = () => { + drawGraph(); + }, [drawGraph]); + + // 容器大小变化时触发重绘 + useEffect(() => { + const container = containerRef.current; + if (!container) return; + const observer = new ResizeObserver(() => { drawGraph(); - animFrameRef.current = requestAnimationFrame(animate); - }; - animFrameRef.current = requestAnimationFrame(animate); - return () => cancelAnimationFrame(animFrameRef.current); + }); + observer.observe(container); + return () => observer.disconnect(); }, [drawGraph]); // ── Mouse interaction handlers ──