Dashboard: run unchanged when a portal serves it

The same bundle is served by a portal under /i/{id}, so it reads its API base,
credential and router basepath from an injected config instead of the build-time
URL and localStorage. A normal installation finds no config and behaves exactly
as before; the credential deliberately never touches localStorage, since two
installations open in one browser share an origin and would overwrite each
other's session.

The websocket URL was resolving an absolute path against the base, which
discards the base's own path — harmless until the base gained one, then it
aimed the socket at the wrong host entirely.

Connection state gets a store of its own, apart from the engine's: the proxy's
503 carries {offline, last_seen}, which raises a banner naming when the
installation was last heard from and turns a failed mutation into 'not
delivered' rather than a generic error. The screen keeps its last data
underneath, since stale readings with a timestamp beat a blank page. A
reconnecting socket invalidates every query, because whatever happened while it
was down was missed.

Verified in a browser against a real hub and installation: the full UI loads
through the tunnel with no console errors, and killing the installation raises
the banner within a poll.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtBzdDyLsmDaF1W7DLYtYM
This commit is contained in:
2026-08-19 17:09:53 +02:00
co-authored by Claude Opus 5
parent f4b81507d1
commit 32d8b42682
11 changed files with 254 additions and 12 deletions
@@ -0,0 +1,52 @@
import { WifiOff } from "lucide-react"
import { AnimatePresence, motion } from "motion/react"
import { useSyncExternalStore } from "react"
import { ago } from "@/components/Health/queries"
import { connectionStore } from "@/lib/connectionStore"
import { fadeIn } from "@/lib/motion"
import { isPortal } from "@/lib/portal"
/**
* Says when the installation cannot be reached, and when it was last heard
* from.
*
* Only ever shown under a portal: a local install cannot lose contact with
* itself. The screen underneath keeps its last data rather than blanking —
* stale readings with a timestamp are more use than an empty page, which is
* why the banner leads with when we last heard anything.
*/
export function ConnectionBanner() {
const connection = useSyncExternalStore(
connectionStore.subscribe,
connectionStore.snapshot,
connectionStore.snapshot,
)
if (!isPortal()) return null
return (
<AnimatePresence>
{connection.offline && (
<motion.div
variants={fadeIn}
initial="hidden"
animate="visible"
exit="hidden"
role="status"
aria-live="polite"
className="pointer-events-none fixed inset-x-0 top-4 z-50 flex justify-center px-4"
>
<div className="flex items-center gap-2 rounded-full border border-border bg-card/80 px-4 py-2 text-sm shadow-e2 backdrop-blur-md">
<WifiOff className="size-4 shrink-0 text-muted-foreground" />
<span className="font-medium">Installation offline</span>
<span className="text-muted-foreground">
{connection.lastSeen
? `last seen ${ago(connection.lastSeen / 1000)} — reconnecting…`
: "reconnecting…"}
</span>
</div>
</motion.div>
)}
</AnimatePresence>
)
}