From 013788d56651ddd72d119e821b2a52589d0a13dd Mon Sep 17 00:00:00 2001 From: AmirReza Jamali Date: Tue, 28 Apr 2026 14:01:07 +0330 Subject: [PATCH] feat(map): enhance map component with ref for container and cleanup logic --- .../(home)/_components/region-labels/map.tsx | 25 ++++++++++++++++--- src/components/Charts/used-devices/index.tsx | 6 ++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/app/(home)/_components/region-labels/map.tsx b/src/app/(home)/_components/region-labels/map.tsx index e370b69..1e81f11 100644 --- a/src/app/(home)/_components/region-labels/map.tsx +++ b/src/app/(home)/_components/region-labels/map.tsx @@ -1,13 +1,23 @@ "use client"; import jsVectorMap from "jsvectormap"; -import { useEffect } from "react"; +import { useEffect, useRef } from "react"; import "@/js/us-aea-en"; export default function Map() { + const mapContainerRef = useRef(null); + useEffect(() => { - new jsVectorMap({ + let map: InstanceType | null = null; + const container = mapContainerRef.current; + + if (!container) return; + + // Dev Strict Mode can run effects twice; clear old markup before re-init. + container.innerHTML = ""; + + map = new jsVectorMap({ selector: "#mapOne", map: "us_aea_en", zoomButtons: true, @@ -37,11 +47,20 @@ export default function Map() { }, }, }); + + return () => { + try { + map?.destroy?.(); + } catch { + // jsVectorMap can throw during React Strict Mode cleanup in dev. + } + container.innerHTML = ""; + }; }, []); return (
-
+
); } diff --git a/src/components/Charts/used-devices/index.tsx b/src/components/Charts/used-devices/index.tsx index aa4f0cc..8162b13 100644 --- a/src/components/Charts/used-devices/index.tsx +++ b/src/components/Charts/used-devices/index.tsx @@ -17,11 +17,11 @@ export async function UsedDevices({ return (
-
+

Used Devices

@@ -29,7 +29,7 @@ export async function UsedDevices({
-
+