diff --git a/frontend/biome.json b/frontend/biome.json index 9a2a822..7063ffa 100644 --- a/frontend/biome.json +++ b/frontend/biome.json @@ -105,7 +105,8 @@ }, "javascript": { "formatter": { - "quoteStyle": "double" + "quoteStyle": "double", + "lineEnding": "lf" } } } diff --git a/frontend/src/app/page.js b/frontend/src/app/page.js index 5499b8e..4429ca1 100644 --- a/frontend/src/app/page.js +++ b/frontend/src/app/page.js @@ -77,10 +77,10 @@ export default function Home() { return (
- */}
Block: {blockNumber} diff --git a/frontend/src/components/Graph.js b/frontend/src/components/Graph.js index 917e5ba..b2c2d7b 100644 --- a/frontend/src/components/Graph.js +++ b/frontend/src/components/Graph.js @@ -1,53 +1,70 @@ -import { Graph } from "graphology"; +import dynamic from "next/dynamic"; import React, { useEffect, useRef } from "react"; -import Sigma from "sigma"; - -const GraphComponent = ({ graphData }) => { - const containerRef = useRef(null); - const sigmaInstanceRef = useRef(null); - - useEffect(() => { - if (containerRef.current) { - const graph = new Graph(); - for (const node of graphData.nodes) { - graph.addNode(node.id, { ...node }); - } - for (const edge of graphData.edges) { - graph.addEdge(edge.source, edge.target, { ...edge }); - } - sigmaInstanceRef.current = new Sigma(graph, containerRef.current); - } - - return () => { - sigmaInstanceRef.current?.kill(); - }; - }, [graphData]); - - useEffect(() => { - const container = containerRef.current; - - if (container) { - const resizeObserver = new ResizeObserver(() => { - sigmaInstanceRef.current?.refresh(); - }); - - resizeObserver.observe(container); - - return () => { - resizeObserver.disconnect(); + +// Dynamically import Sigma, ensuring it only loads on the client side +const GraphComponent = dynamic( + () => + import("sigma").then((Sigma) => { + return ({ graphData }) => { + const containerRef = useRef(null); + const sigmaInstanceRef = useRef(null); + + useEffect(() => { + if (containerRef.current) { + const { Graph } = require("graphology"); // Dynamically import graphology on the client side + const graph = new Graph(); + + // Add nodes and edges to the graph + for (const node of graphData.nodes) { + graph.addNode(node.id, { ...node }); + } + for (const edge of graphData.edges) { + graph.addEdge(edge.source, edge.target, { ...edge }); + } + + // Initialize Sigma instance + sigmaInstanceRef.current = new Sigma.default( + graph, + containerRef.current, + ); + } + + // Clean up the Sigma instance on component unmount + return () => { + sigmaInstanceRef.current?.kill(); + }; + }, [graphData]); + + useEffect(() => { + const container = containerRef.current; + + if (container) { + const resizeObserver = new ResizeObserver(() => { + sigmaInstanceRef.current?.refresh(); + }); + + // Observe container resizing to refresh the Sigma instance + resizeObserver.observe(container); + + // Disconnect the ResizeObserver on cleanup + return () => { + resizeObserver.disconnect(); + }; + } + }, []); + + return ( +
+ ); }; - } - }, []); - - return ( -
- ); -}; + }), + { ssr: false }, // Disable SSR +); export default GraphComponent;