ssr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ssr renders Svelte pages on the server by running the app's server bundle in embedded QuickJS VMs. It is pure Go: no cgo and no Node.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("ssr: render timed out")

ErrTimeout is returned when a render exceeds the pool's timeout.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	URL    string // the Vite dev server, e.g. http://127.0.0.1:5174
	Client *http.Client
}

Dev renders through the Vite dev server, so server rendering uses the same up-to-date modules as hot module replacement.

func (*Dev) Render

func (d *Dev) Render(ctx context.Context, payload []byte, href string) (Result, error)

Render implements Renderer.

type Options

type Options struct {
	// Workers is the number of VMs, and so the number of concurrent
	// renders. The default is GOMAXPROCS.
	Workers int
	// Timeout bounds a single render. The default is 5 seconds.
	Timeout time.Duration
	// MemoryLimit caps each VM's heap, in bytes. The default is 256 MiB.
	MemoryLimit uintptr
	// Logger receives console output from server-side code.
	Logger *slog.Logger
}

Options configure a Pool.

type Pool

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

Pool renders with a fixed number of reusable VMs. VMs are created on demand; a VM that times out or fails is discarded and replaced.

func NewPool

func NewPool(bundle string, opts Options) (*Pool, error)

NewPool compiles bundle, which must define globalThis.__tern_render, and returns a pool ready to render. It creates one VM up front so a broken bundle fails at startup rather than on the first request.

func (*Pool) Close

func (p *Pool) Close() error

Close releases the pool's VMs. Renders in progress finish first.

func (*Pool) Render

func (p *Pool) Render(ctx context.Context, payload []byte, href string) (Result, error)

Render renders payload, waiting for a free VM if all are busy.

type Renderer

type Renderer interface {
	Render(ctx context.Context, payload []byte, href string) (Result, error)
}

Renderer renders a page payload. href is the page's absolute URL.

type Result

type Result struct {
	Head string `json:"head"`
	Body string `json:"body"`
	// Skip reports that the payload is not something the server renders.
	Skip bool `json:"skip"`
}

Result is a rendered page.

Jump to

Keyboard shortcuts

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