Skip to content

Commit b68460a

Browse files
authored
Merge pull request Stellar-IndigoPay#800 from Jayking40/main
Fix runtime CDN dependency for Leaflet CSS
2 parents 64e3b30 + eca3880 commit b68460a

4 files changed

Lines changed: 5 additions & 27 deletions

File tree

frontend/components/ProjectMap.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,9 @@ interface ProjectMapProps {
3333

3434
// ── Component ──────────────────────────────────────────────────────────────────
3535

36+
import "leaflet/dist/leaflet.css";
37+
3638
export default function ProjectMap({ projects }: ProjectMapProps) {
37-
// Leaflet needs the CSS — import it once at runtime (not at module level so
38-
// it doesn't run on the server via accidental imports).
39-
useEffect(() => {
40-
// Only import once; subsequent HMR reloads skip this because the link
41-
// element already exists in the document head.
42-
if (
43-
typeof document !== "undefined" &&
44-
!document.head.querySelector('link[href*="leaflet"]')
45-
) {
46-
const link = document.createElement("link");
47-
link.rel = "stylesheet";
48-
link.href = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css";
49-
link.integrity = "sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=";
50-
link.crossOrigin = "anonymous";
51-
document.head.appendChild(link);
52-
}
53-
}, []);
5439

5540
return (
5641
<MapContainer

frontend/middleware.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ const LEAFLET_TILE_SOURCES = [
1616
"https://c.tile.openstreetmap.org",
1717
].join(" ");
1818

19-
// unpkg.com serves the Leaflet CSS loaded dynamically in ProjectMap.tsx.
20-
const UNPKG = "https://unpkg.com";
21-
2219
export function buildCsp(nonce: string, isWidget: boolean): string {
2320
// API origin: 'self' covers same-origin deploys; NEXT_PUBLIC_API_URL covers
2421
// deployed backends and CI/E2E environments (e.g. http://localhost:4000).
@@ -49,8 +46,7 @@ export function buildCsp(nonce: string, isWidget: boolean): string {
4946
// nonce tags the Next.js script injection; strict-dynamic propagates trust
5047
// to the bundles it loads (inline scripts are nonce'd, never inline-allowed).
5148
`script-src ${scriptSrc}`,
52-
// unpkg serves the Leaflet CSS stylesheet.
53-
`style-src 'self' 'unsafe-inline' https://fonts.googleapis.com ${UNPKG}`,
49+
`style-src 'self' 'unsafe-inline' https://fonts.googleapis.com`,
5450
"font-src 'self' https://fonts.gstatic.com",
5551
// OSM tile images are loaded as <img> elements by Leaflet TileLayer.
5652
// Leaflet marker icons use data: URIs (our inline SVG divIcon).

frontend/next.config.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ const LEAFLET_TILE_SOURCES = [
4040
"https://c.tile.openstreetmap.org",
4141
].join(" ");
4242

43-
// unpkg serves the Leaflet CSS (dynamically injected by ProjectMap.tsx)
44-
const UNPKG = "https://unpkg.com";
45-
4643
function buildStaticCsp(allowFraming = false) {
4744
const frameAncestors = allowFraming
4845
? "frame-ancestors *"
@@ -51,8 +48,7 @@ function buildStaticCsp(allowFraming = false) {
5148
"default-src 'self'",
5249
// static fallback uses placeholder nonce for inline scripts; actual nonce injected by middleware
5350
`script-src 'self' 'nonce-{nonce}' https://*.stellar.org`,
54-
// unpkg serves the Leaflet CSS stylesheet loaded dynamically in ProjectMap.
55-
`style-src 'self' 'unsafe-inline' https://fonts.googleapis.com ${UNPKG}`,
51+
`style-src 'self' 'unsafe-inline' https://fonts.googleapis.com`,
5652
"font-src 'self' https://fonts.gstatic.com",
5753
// OSM tiles loaded as images; Leaflet marker icons use data: URIs.
5854
`img-src 'self' data: blob: ${LEAFLET_TILE_SOURCES}`,

frontend/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)