Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions apps/www/components/tool-ui/geo-map/_adapter.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
/**
* Adapter: UI and utility re-exports for copy-standalone portability.
*
* This file must stay free of leaflet: the facade imports it, and leaflet
* reads `window` at module scope. Map primitives live in `_leaflet-adapter`,
* which only client-only modules may import.
*
* When copying this component to another project, update these imports
* to match your project's paths:
*
* cn → Your Tailwind merge utility (e.g., "@/lib/utils", "~/lib/cn")
* Leaflet → map primitives from react-leaflet
* cn → Your Tailwind merge utility (e.g., "@/lib/utils", "~/lib/cn")
*/

export { cn } from "@/lib/utils";
export {
CircleMarker,
MapContainer,
Marker,
Polyline,
Popup,
TileLayer,
Tooltip,
ZoomControl,
useMap,
useMapEvents,
} from "react-leaflet";
25 changes: 25 additions & 0 deletions apps/www/components/tool-ui/geo-map/_leaflet-adapter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Adapter: react-leaflet re-exports for copy-standalone portability.
*
* Leaflet reads `window` at module scope, so only modules that already live
* behind the client-only boundary (the engine and its overlays) may import
* from this file. The facade stays on `_adapter` and must never depend on it.
*
* When copying this component to another project, update these imports
* to match your project's paths:
*
* Leaflet → map primitives from react-leaflet
*/

export {
CircleMarker,
MapContainer,
Marker,
Polyline,
Popup,
TileLayer,
Tooltip,
ZoomControl,
useMap,
useMapEvents,
} from "react-leaflet";
2 changes: 1 addition & 1 deletion apps/www/components/tool-ui/geo-map/geo-map-engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ZoomControl,
useMap,
useMapEvents,
} from "./_adapter";
} from "./_leaflet-adapter";
Comment thread
okisdev marked this conversation as resolved.
import { createClusterIcon, resolveMarkerIcon } from "./geo-map-icons";
Comment thread
okisdev marked this conversation as resolved.
import { GeoMapOverlays } from "./geo-map-overlays";
import type {
Expand Down
3 changes: 2 additions & 1 deletion apps/www/components/tool-ui/geo-map/geo-map-overlays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useMemo, useState } from "react";

import { Popup, Tooltip, cn } from "./_adapter";
import { cn } from "./_adapter";
import { Popup, Tooltip } from "./_leaflet-adapter";

function GeoMapPopupContent({
label,
Expand Down
9 changes: 8 additions & 1 deletion apps/www/components/tool-ui/geo-map/geo-map.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"use client";

import dynamic from "next/dynamic";
import { memo, useEffect, useState } from "react";
Comment thread
okisdev marked this conversation as resolved.
import { cn } from "./_adapter";
import { GeoMapEngine } from "./geo-map-engine";
import styles from "./geo-map-theme.module.css";
import type { GeoMapProps, GeoMapStyle } from "./schema";

// Leaflet touches `window` at module scope, so the engine must never be
// evaluated during SSR; every GeoMap consumer inherits this guard.
Comment thread
okisdev marked this conversation as resolved.
const GeoMapEngine = dynamic(
() => import("./geo-map-engine").then((m) => m.GeoMapEngine),
{ ssr: false },
);

const LIGHT_TILE_URL =
"https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png";
const DARK_TILE_URL =
Expand Down
10 changes: 10 additions & 0 deletions apps/www/lib/tests/geo-map-ssr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";

describe("geo-map SSR safety", () => {
it("imports the facade without evaluating leaflet", async () => {
expect(globalThis.window).toBeUndefined();
await expect(
import("@/components/tool-ui/geo-map"),
).resolves.toHaveProperty("GeoMap");
});
});
2 changes: 1 addition & 1 deletion apps/www/lib/tests/tool-ui/geo-map/spatial.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test, vi } from "vitest";

vi.mock("@/components/tool-ui/geo-map/_adapter", () => ({
vi.mock("@/components/tool-ui/geo-map/_leaflet-adapter", () => ({
CircleMarker: () => null,
MapContainer: () => null,
Marker: () => null,
Expand Down
15 changes: 11 additions & 4 deletions apps/www/public/r/geo-map.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions apps/www/public/r/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@
"description": "Display geolocated entities and fleet positions.",
"dependencies": [
"leaflet",
"next",
"react-leaflet",
"supercluster",
"zod"
Expand All @@ -541,6 +542,11 @@
"type": "registry:component",
"target": "components/tool-ui/geo-map/_adapter.tsx"
},
{
"path": "components/tool-ui/geo-map/_leaflet-adapter.tsx",
"type": "registry:component",
"target": "components/tool-ui/geo-map/_leaflet-adapter.tsx"
},
{
"path": "components/tool-ui/geo-map/geo-map-engine.tsx",
"type": "registry:component",
Expand Down
Loading