From f0f02b3c4c3ac38bfad38dc1a9d19621df5ed019 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Fri, 10 Apr 2026 21:01:07 -0400 Subject: [PATCH] fix: remove unnecessary remix-utils dependency --- app/root.tsx | 2 -- app/routes/ssh/page.tsx | 11 ----------- app/routes/ssh/wasm.client.ts | 20 +++++++++++++++++++- package.json | 1 - 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index 4185170..cba99c5 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -1,6 +1,5 @@ import type { MetaFunction } from "react-router"; import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router"; -import { ExternalScripts } from "remix-utils/external-scripts"; import { LiveDataProvider } from "~/utils/live-data"; import ToastProvider from "~/utils/toast-provider"; @@ -38,7 +37,6 @@ export function Layout({ children }: { readonly children: React.ReactNode }) { - diff --git a/app/routes/ssh/page.tsx b/app/routes/ssh/page.tsx index a46520e..8d31673 100644 --- a/app/routes/ssh/page.tsx +++ b/app/routes/ssh/page.tsx @@ -1,7 +1,6 @@ import { Loader2, WifiOff } from "lucide-react"; import { useEffect, useState } from "react"; import { data, isRouteErrorResponse, type ShouldRevalidateFunction } from "react-router"; -import { ExternalScriptsHandle } from "remix-utils/external-scripts"; import Button from "~/components/button"; import Card from "~/components/card"; @@ -112,16 +111,6 @@ export const links: Route.LinksFunction = () => [ }, ]; -export const handle: ExternalScriptsHandle = { - scripts: [ - { - src: WASM_HELPER_URL, - crossOrigin: "anonymous", - preload: true, - }, - ], -}; - export default function Page({ loaderData }: Route.ComponentProps) { const { hostname, username, offline, node } = loaderData; diff --git a/app/routes/ssh/wasm.client.ts b/app/routes/ssh/wasm.client.ts index 883c145..e656a1c 100644 --- a/app/routes/ssh/wasm.client.ts +++ b/app/routes/ssh/wasm.client.ts @@ -1,4 +1,5 @@ const WASM_MODULE_URL = `${__PREFIX__}/hp_ssh.wasm`; +const WASM_HELPER_URL = `${__PREFIX__}/wasm_exec.js`; declare global { type HeadplaneSSHFactory = (config: HeadplaneSSHConfig) => HeadplaneSSH; @@ -44,12 +45,29 @@ export interface TunnelSession { let resolvedFactory: Promise | null = null; +function loadGoHelper(): Promise { + if (typeof globalThis.Go !== "undefined") { + return Promise.resolve(); + } + + return new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.src = WASM_HELPER_URL; + script.crossOrigin = "anonymous"; + script.onload = () => resolve(); + script.onerror = () => reject(new Error("Failed to load Go WASM helper")); + document.head.appendChild(script); + }); +} + /** * One-shot function that loads the Go WASM binary and returns the SSH factory. - * It expects the Go WASM helper to be loaded, and will error if called before. + * Automatically loads the Go JS helper if it hasn't been loaded yet. */ export async function loadHeadplaneWASM(): Promise { if (!resolvedFactory) { + await loadGoHelper(); + const go = new Go(); const result = await WebAssembly.instantiateStreaming(fetch(WASM_MODULE_URL), go.importObject); diff --git a/package.json b/package.json index 7e5db25..7348d88 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "react-router": "^7.14.0", "react-router-dom": "^7.14.0", "react-router-hono-server": "2.25.2", - "remix-utils": "^9.3.1", "restty": "^0.1.35", "tailwind-merge": "3.5.0", "ulidx": "2.4.1",