runtime

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 9 Imported by: 0

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 core runtime (`runtime.js`) — the one-script substrate for SPA navigation, signals, widgets, hydration, and demand-module loading. Served at `/__gofastr/runtime.js`.

  • Per-module bundles (`src/<name>.js`) — payloads loaded on demand via `__gofastr.loadModule(name)`. RPC is prefetched when its marker exists and awaited by the core delegation bridge; optional UI behaviors use the same loader.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorSchemeJS

func ColorSchemeJS() (string, error)

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 EmbedJS added in v0.49.0

func EmbedJS() (string, error)

EmbedJS returns the `embed` runtime composition — the bundle served inside an embedded surface's iframe.

Its budget is looser than the core runtime's on purpose: it loads inside a frame and blocks nothing on the host page. It is still budgeted, because how fast an embed paints is the product.

func EmbedLoaderJS added in v0.49.0

func EmbedLoaderJS() (string, error)

EmbedLoaderJS returns the loader a customer pastes into their own page.

This is the tightest budget in the repo: it lands on a stranger's critical path, on a site whose performance we do not control and whose owner did not choose GoFastr. It creates the iframe, hands over the nonce by postMessage, and resizes. Anything else belongs inside the frame.

func Module

func Module(name string) (string, bool)

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

func ModuleSize(name string) int

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 MustEmbedJS added in v0.49.0

func MustEmbedJS() string

MustEmbedJS returns the embed runtime or panics.

func MustEmbedLoaderJS added in v0.49.0

func MustEmbedLoaderJS() string

MustEmbedLoaderJS returns the embed loader or panics.

func MustRuntimeJS

func MustRuntimeJS() string

MustRuntimeJS returns the bundled runtime or panics.

func MustStaticJS added in v0.48.0

func MustStaticJS() string

MustStaticJS returns the static runtime or panics.

func NeededModules

func NeededModules(pageHTML string) []string

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 with an attribute-name boundary check — not a real HTML parse. The boundary check keeps one marker from matching inside a longer attribute name (data-fui-compute must not fire on data-fui-computed). The cost of a residual false positive is one wasted module fetch (no correctness impact).

func RuntimeJS

func RuntimeJS() (string, error)

RuntimeJS returns the composed runtime — the single-file IIFE every page ships by default. Assembled from the fragment files once, then minified (or returned verbatim when RUNTIME_NOMINIFY=1).

func RuntimeSize

func RuntimeSize() int

RuntimeSize returns the byte size of the bundled runtime.

func StaticJS added in v0.48.0

func StaticJS() (string, error)

StaticJS returns the `static` runtime composition used by serverless exports. rpc-stub intercepts server-backed controls and boot skips the RPC module marker. widgets-boot-static reads the dumped widget catalog so overlays still resolve from exported files.

Types

This section is empty.

Directories

Path Synopsis
Package minify implements a token-aware JavaScript minifier used to shrink the embedded runtime sources before they're served.
Package minify implements a token-aware JavaScript minifier used to shrink the embedded runtime sources before they're served.

Jump to

Keyboard shortcuts

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