Documentation
¶
Overview ¶
Package runtime provides the GoFastr client-side JavaScript runtime as an embedded resource. The runtime handles event delegation, component hydration on first interaction, and SSE listeners for server-driven islands.
Use RuntimeJS() to get the JavaScript source as a string, or RuntimeSize() to check the size of the runtime.
Package runtime ships the framework's client-side JavaScript runtime.
Two surfaces are exposed:
The bundled runtime (`runtime.js`) — the one-script payload that handles every framework primitive (dispatchRPC, SPA router, screen cache, signals, widgets, etc). Served at `/__gofastr/runtime.js`. This is the default surface.
Per-module bundles (`src/<name>.js`) — small payloads loaded on demand via `__gofastr.loadModule(name)`. Used for the optional code-splitting path; pages opt into individual modules instead of the bundled runtime when bundle size matters.
The HTTP server (core-ui/widget/server.go) consumes Module(name) + ModuleNames() to wire `/__gofastr/runtime/<name>.js` routes; the uihost emits `<link rel="modulepreload">` tags per page based on the components rendered on it.
Index ¶
- func ColorSchemeJS() (string, error)
- func DemandLoadModuleNames() []string
- func Module(name string) (string, bool)
- func ModuleNames() []string
- func ModuleSize(name string) int
- func MustRuntimeJS() string
- func NeededModules(pageHTML string) []string
- func RuntimeJS() (string, error)
- func RuntimeSize() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorSchemeJS ¶
ColorSchemeJS returns the color-scheme bootstrap script — a tiny synchronous snippet meant to ship at the TOP of <head> so dark-mode CSS tokens take effect during the same first paint that hits the page. Reads localStorage("gofastr.colorScheme") + the OS prefers-color-scheme hint, then sets <html data-color-scheme="…"> and a matching <meta name="color-scheme">.
Apps that ship a theme toggle call `window.__gofastr_colorScheme.set('auto'|'light'|'dark')` to override the OS preference.
func DemandLoadModuleNames ¶
func DemandLoadModuleNames() []string
DemandLoadModuleNames returns the unique sorted list of every module referenced by the demand-load table. Used by tests to verify every declared module actually has a corresponding src/<name>.js file.
func Module ¶
Module returns the source of a single split runtime module by name (e.g. "fileupload"). Used by the HTTP server to serve /__gofastr/runtime/<name>.js. Returns "", false when the module is not embedded. Minified on first read (cached).
func ModuleNames ¶
func ModuleNames() []string
ModuleNames returns the sorted list of split modules currently embedded. Each name maps 1:1 to a /__gofastr/runtime/<name>.js URL.
func ModuleSize ¶
ModuleSize returns the byte size of a single embedded module, or 0 if the module isn't present. Used by tests asserting per-module size budgets.
func MustRuntimeJS ¶
func MustRuntimeJS() string
MustRuntimeJS returns the bundled runtime or panics.
func NeededModules ¶
NeededModules returns the deduplicated, sorted list of demand-load runtime modules whose marker substring appears in pageHTML. Used by the framework's UI host to emit <link rel="modulepreload"> tags in <head> per page, kicking off module fetches in parallel with the initial paint.
Matches are substring containment — not a real HTML parse. The markers are unambiguous attribute prefixes ("data-fui-*"), so false positives are vanishingly rare and the cost of a false positive is one wasted module fetch (no correctness impact).
Types ¶
This section is empty.