spa

package
v0.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package spa provides a unified SPA (Single-Page Application) loader for wick's Vite-built Svelte frontends. It handles:

  1. FS selection — compile-time embed.FS in production; os.DirFS when WICK_DEV_REPO_ROOT is set so Vite watch rebuilds are served without recompiling Go.

  2. Asset URL resolution — reads the hashed bundle src from each app's index.html (multi-app: one dist/ root holds dist/<app>/index.html). Cached per-app in production; re-read on every call in live-disk mode.

  3. Dev reload — a single global SSE endpoint (/_dev/reload) that watches all registered dist/ directories and broadcasts a "reload" event to every connected browser tab whenever any bundle rebuilds. Only active when WICK_DEV_REPO_ROOT is set. Call RegisterGlobalHandler(mux) once in the root server; ui.Layout injects DevReloadScript() unconditionally (returns "" in production).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DevReloadScript

func DevReloadScript() string

DevReloadScript returns the inline <script> tag that connects to /_dev/reload and auto-reloads the page on each build. Returns "" when WICK_DEV_REPO_ROOT is not set (production). Safe to inject unconditionally.

func RegisterGlobalHandler

func RegisterGlobalHandler(mux *http.ServeMux)

RegisterGlobalHandler registers GET /_dev/reload on mux only when WICK_DEV_REPO_ROOT is set. No-op otherwise — call unconditionally in server.

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader is the live-disk-aware SPA filesystem + asset-URL resolver for one dist/ root. A root holds one or more apps at dist/<app>/. Create with New.

func New

func New(embedded fs.FS, repoRelDir string) *Loader

New creates a Loader for a single dist/ root and auto-registers it in the global dev-reload registry when WICK_DEV_REPO_ROOT is set.

  • embedded: compile-time embed.FS (must contain dist/...)
  • repoRelDir: repo-root-relative path to the dir holding dist/, e.g. "internal/manager" or "internal/tools/agents"

When WICK_DEV_REPO_ROOT is set and dist/ exists on disk, the loader switches to os.DirFS so Vite watch rebuilds surface without a Go recompile.

func (*Loader) AssetURL

func (l *Loader) AssetURL(app, fallbackBase string) string

AssetURL returns the absolute URL of the hashed entry .js bundle for app, read from dist/<app>/index.html. fallbackBase is the URL prefix used to build the asset URL when index.html has no script tag (rare: a hand-rolled dist tree) — e.g. "/manager/_app/assets". Returns "" when not built yet.

Cached per-app in production; re-read on every call in live-disk mode so a Vite rebuild's new hash surfaces on the next render.

func (*Loader) FS

func (l *Loader) FS() fs.FS

FS returns the active filesystem (embed or live-disk), rooted so that dist/<app>/... paths resolve.

func (*Loader) IsLiveDisk

func (l *Loader) IsLiveDisk() bool

IsLiveDisk reports whether live-disk mode is active.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL