ssr
Joins the static parts of a server template with its dynamic holes into trusted markup: the function compiled server output calls for each element tree.
Joins the static parts of a server template with its dynamic holes into trusted markup: the
function compiled server output calls for each element tree. Holes are inserted unchanged, so each
must already be escaped (the output of escape, ssrAttribute, ssrClass, ...) or an SsrNode;
any other value throws, so a raw user value cannot reach the markup.
Import#
ts
import { ssr } from "@shadow-js/web/server";
Signature#
ts
function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode
Parameters#
| Name | Description |
|---|---|
parts |
The static markup, one more entry than there are holes. |
holes |
The dynamic parts: strings produced by the escaping helpers, or SsrNode values. |
Returns#
The markup as a trusted SsrNode, which escape writes without encoding.
Throws#
- TypeError when
partsis not an array ofholes.length + 1entries, or when a hole is not a string or anSsrNode.
Examples#
ts
import { escape, renderToString, ssr } from "@shadow-js/web/server";
const name = "<Ada>";
const html = renderToString(() => ssr(["<p>Hello, ", "</p>"], escape(name)));
// "<p>Hello, <Ada></p>"