variable / @typed/template

HtmlRenderTemplate

A Layer that provides the RenderTemplate service implemented for HTML string generation.

Using this layer enables templates to be rendered as HTML strings (e.g., for SSR) rather than DOM nodes. It sets the RefSubject.CurrentComputedBehavior to "one", indicating a single-pass render approach typical for HTML generation.

Package version
1.0.0-beta.7
Category
Hydratable HTML rendering
Since
1.0.0

Import

import { HtmlRenderTemplate } from "@typed/template";

Signatures

export declare const HtmlRenderTemplate: Layer.Layer<RenderTemplate, never, never>;

Why

The Layer supplies the same RenderTemplate service consumed by html, so templates are renderer-independent while SSR remains an ordered Fx of chunks. Parsed templates and compiled chunks are cached by template-literal identity.

Ownership and lifetime

The provided service and its caches live for the Layer Scope. Each rendered Fx owns its dynamic subscriptions until completion or interruption. The layer intentionally selects the first value from live sources for finite SSR.

Trust boundary

Literal segments are author markup. Dynamic text and attributes are escaped; event, ref, property, prototype-sensitive, and unsafe spread keys are not serialized as HTML.

Examples

import { Effect } from "effect"
import { html } from "@typed/template"
import { renderToHtmlString, HtmlRenderTemplate } from "@typed/template/Html"

const program = Effect.scoped(Effect.gen(function* () {
  const template = html`<div>Hello, ${"world"}!</div>`

  const htmlString = yield* renderToHtmlString(template).pipe(
    Effect.provide(HtmlRenderTemplate)
  )

  // Use for SSR
  return htmlString
}))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source