Markup as HTML
Components on the server — design
Status: implemented are markup as HTML, components of the server, their results,
Responsegoing up,Content<T>, component values with a result, decorators with guards, wrappers that take the body and the request context, routes, androoklang/server; the server of the site,site/server/main.rk, is written with them, and the guide has a section on them. The decisions are collected at the end of the document, together with what is not decided yet. Server markup, components androoklang/serverremain experimental in 1.x and may change between releases.
This document builds on components.md: components, decorators, context, components as values. It describes only what is different on the server.
const name = "Ann & Bob"
const link = <a href="/users?sort=name" class="nav">Hello, {name}</a> // Html
const link = $$html`<a href="/users?sort=name" class="nav">Hello, ${name}</a>`
- The type of markup is
Html, HTML that is known to be safe. It is a type of its own: astringis not anHtml, nor anHtmlastring. In JS it is an object of the runtime whosetextis the HTML, so that the runtime tells it from text too;String(page)and`${page}`give the text. - Attributes are checked by the DOM, as in the browser:
<input value={1}>and<a hreff="/">are errors. The types come from the samelib.domorsrc/checker/dom.ts, only the result isHtmlinstead ofHTMLAnchorElement. - Escaping. Text and the values of attributes are escaped; an
Htmlis put in as it is. A string that is known to be HTML (from a Markdown renderer, say) becomes one withhtml(s):<article>{html(rendered)}</article>. That is the only way around escaping, so a search forhtml(finds every place that can inject markup. - Children are
Html, strings, numbers, arrays of them andnull, as in the browser. AResponseamong them stops the rendering (see "AResponsegoes up"); any other value is a compile error:a component of type User[] cannot be in markup; return it, or show its fields, e.g. {user.name}. class={[...]},boolin ARIA attributes, SVG work as in the browser. Aboolattribute without a value,<input disabled={off}>, is written only when it is true.<html>at the top of a result gets<!doctype html>in front of it.- What the browser has and the server has not is an error that says what to do instead:
onClickand the other handlers:"onClick" has no meaning on the server: markup there is a string; make a client component with @html-tag for code that runs in the browser;bind:,ref,state,derived,effect,mount;stateat the top level of a module: on the server it would be shared by all requests at once. A value of the module that requests share on purpose (a cache, a pool of connections) is aletor aconst.