From 44e7639124a130e842d3eae088b36aec94325bad Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Sat, 14 Mar 2026 12:24:54 -0700 Subject: [PATCH] fix(rnetwork): switch to unpkg CDN with dynamic fallback for 3d-force-graph jsdelivr was returning 503. Switch primary CDN to unpkg and add a dynamic fallback loader that tries both CDNs if the initial script tag fails. Co-Authored-By: Claude Opus 4.6 --- .../rnetwork/components/folk-graph-viewer.ts | 24 +++++++++++++++++-- modules/rnetwork/mod.ts | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/rnetwork/components/folk-graph-viewer.ts b/modules/rnetwork/components/folk-graph-viewer.ts index 0234670..6e127e4 100644 --- a/modules/rnetwork/components/folk-graph-viewer.ts +++ b/modules/rnetwork/components/folk-graph-viewer.ts @@ -550,8 +550,28 @@ class FolkGraphViewer extends HTMLElement { this.graphContainer = container; try { - const ForceGraph3D = (window as any).ForceGraph3D; - if (!ForceGraph3D) throw new Error("ForceGraph3D not loaded — check UMD script tag"); + let ForceGraph3D = (window as any).ForceGraph3D; + if (!ForceGraph3D) { + // CDN script tag may have failed (503 etc) — try loading dynamically with fallback + const cdns = [ + "https://unpkg.com/3d-force-graph@1.73.4/dist/3d-force-graph.min.js", + "https://cdn.jsdelivr.net/npm/3d-force-graph@1.73.4/dist/3d-force-graph.min.js", + ]; + for (const url of cdns) { + try { + await new Promise((resolve, reject) => { + const s = document.createElement("script"); + s.src = url; + s.onload = () => resolve(); + s.onerror = () => reject(); + document.head.appendChild(s); + }); + ForceGraph3D = (window as any).ForceGraph3D; + if (ForceGraph3D) break; + } catch { /* try next CDN */ } + } + if (!ForceGraph3D) throw new Error("ForceGraph3D failed to load from all CDN sources"); + } // Pre-load THREE so nodeThreeObject callback is synchronous. // Import from the same module the UMD build uses internally diff --git a/modules/rnetwork/mod.ts b/modules/rnetwork/mod.ts index 194f547..2704a9d 100644 --- a/modules/rnetwork/mod.ts +++ b/modules/rnetwork/mod.ts @@ -15,11 +15,11 @@ import { renderLanding } from "./landing"; // ── CDN scripts for Three.js + 3d-force-graph ── // UMD build bundles Three.js + all transitive deps — no bare-specifier issues. // We also provide an importmap for "three" so folk-graph-viewer can import("three") for custom meshes. -const GRAPH3D_HEAD = ` +const GRAPH3D_HEAD = ` `;