ssr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractBody

func ExtractBody(html string) (body, before, after string)

ExtractBody splits an HTML document into (bodyContent, before, after). before includes everything up to and including the opening <body> tag. after includes the closing </body> tag and everything after. If no <body> tag exists, the entire input is returned as bodyContent with empty before and after.

func HashOutput

func HashOutput(html string) string

HashOutput computes a content hash for Phase 2 output comparison. If the hash matches the cached hash, SSR can be skipped for that page.

func ReassembleDocument

func ReassembleDocument(before, ssrBody, after string) string

ReassembleDocument re-inserts SSR'd body content into the document skeleton.

func RenderPage

func RenderPage(command string, html string) (string, error)

RenderPage pipes full page HTML to the command via stdin and returns the transformed HTML from stdout. The command string is parsed into executable + args via strings.Fields.

func RenderPageWithTimeout

func RenderPageWithTimeout(ctx context.Context, command string, html string) (string, error)

RenderPageWithTimeout pipes full page HTML to the command via stdin, respecting the context deadline. The process is killed if the context expires before completion.

func ScanComponents

func ScanComponents(html string) []string

ScanComponents parses HTML and returns unique custom element tag names (tags with hyphens). Returns deduplicated tag names only.

Types

type ComponentMap

type ComponentMap struct {
	// PageToComponents maps page source path → list of component tag names on that page
	PageToComponents map[string][]string `json:"pageToComponents"`
	// ComponentToPages maps component tag → list of page source paths using it
	ComponentToPages map[string][]string `json:"componentToPages"`
	// ComponentDeps maps component tag → list of child component tags
	ComponentDeps map[string][]string `json:"componentDeps"`
	// DefinitionHashes maps component tag → hash of its definition source
	DefinitionHashes map[string]string `json:"definitionHashes"`
}

ComponentMap holds the full component tracking state persisted to .alloy/components.json.

func LoadComponentMap

func LoadComponentMap(dir string) (*ComponentMap, error)

LoadComponentMap reads components.json from the given directory. Returns an empty ComponentMap if the file does not exist (fresh build).

func NewComponentMap

func NewComponentMap() *ComponentMap

NewComponentMap creates an empty component map.

func (*ComponentMap) SaveTo

func (cm *ComponentMap) SaveTo(dir string) error

SaveTo writes the component map to components.json in the given directory.

func (*ComponentMap) ShouldSkipSSR

func (cm *ComponentMap) ShouldSkipSSR(componentTag string, currentDefHash string) bool

ShouldSkipSSR returns true if the component's definition hash hasn't changed, meaning Phase 2 SSR can be skipped for pages using only unchanged components.

type DepGraph

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

DepGraph tracks component-to-component dependencies for invalidation.

func NewDepGraph

func NewDepGraph() *DepGraph

NewDepGraph creates an empty component dependency graph.

func (*DepGraph) AddDependency

func (dg *DepGraph) AddDependency(parent, child string)

AddDependency records that parent uses child in its shadow root.

func (*DepGraph) GetAffected

func (dg *DepGraph) GetAffected(component string) []string

GetAffected returns all components that need re-SSR when the given component changes. Traverses the reverse dependency graph transitively.

func (*DepGraph) InvalidateByDefinition

func (dg *DepGraph) InvalidateByDefinition(componentTag string) []string

InvalidateByDefinition returns all components that need re-rendering when a component definition file changes (detected via file watcher).

type StreamRenderer

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

StreamRenderer manages a persistent SSR process that handles multiple pages via NUL-delimited stdin/stdout messages.

func NewStreamRenderer

func NewStreamRenderer(command string) (*StreamRenderer, error)

NewStreamRenderer starts a persistent process for stream-mode SSR. The process stays alive until Close() is called.

func (*StreamRenderer) Close

func (sr *StreamRenderer) Close() error

Close shuts down the persistent process by closing stdin and waiting for exit.

func (*StreamRenderer) RenderPage

func (sr *StreamRenderer) RenderPage(html string) (string, error)

RenderPage sends HTML to the persistent process via stdin (NUL-terminated) and reads the response from stdout (NUL-terminated).

func (*StreamRenderer) RenderPageWithTimeout

func (sr *StreamRenderer) RenderPageWithTimeout(ctx context.Context, html string) (string, error)

RenderPageWithTimeout sends HTML to the persistent process, respecting the context deadline. If the read exceeds the deadline, the context error is returned.

func (*StreamRenderer) Restart

func (sr *StreamRenderer) Restart() error

Restart kills the current process and starts a new one.

Jump to

Keyboard shortcuts

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