Server rendering and engine binding
Radiant UI views rendered on the server do not register their elements in the browser, so
the module that builds your engine must reach the client: it imports @schema-engine/forms-radiant,
which registers the form hosts and the Radiant UI components they use. The engine is not
serialized into server-rendered markup, so the app assigns it
to each se-form-renderer. Assign it before or after the renderer upgrades: the
hosts below it read the engine from the renderer's context and follow it when it
arrives or changes.
engine is a property only; there is no HTML attribute. The module that builds the engine:
import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
export const formEngine = createRadiantFormEngine({ elements: schemaFormRegistrations });Bind every renderer on the page:
import type { FormRendererElement } from '@schema-engine/forms-radiant';
import { formEngine } from './form-engine';
export function bindEngine(root: ParentNode): void {
for (const renderer of root.querySelectorAll<FormRendererElement>('se-form-renderer')) {
renderer.engine = formEngine;
}
}
bindEngine(document);A client-side router that swaps in a parsed page does not upgrade it first. Assign
the engine to the incoming renderers in the router's eco:before-swap event
(event.detail.newDocument); they upgrade with the engine already set:
import { bindEngine } from './bind-engine';
document.addEventListener('eco:before-swap', (event) => {
bindEngine((event as CustomEvent<{ newDocument: Document }>).detail.newDocument);
});A form that is only rendered on the client passes engine to
FormRenderer and needs none of this.
Layout stylesheet per form
Radiant has no head hoisting, so each form carries a self-contained copy of its layout theme's stylesheet (<style data-se-theme-css="<id>">, about 11 kB raw for the default theme), and compression makes the repeated copies cheap on the wire. Layout themes says why, and how React differs.
A host that also wants the rules in its own head can serve the theme's css; the forms keep their copies, which hold
the same rules:
import { formEngine } from './form-engine';
const { id, css } = formEngine.getLayout();
export const head = `<style data-se-theme-css="${id}">${css}</style>`;