pub struct RenderCtx { /* private fields */ }Expand description
What a render takes beyond PageConfig: the policy’s typed extensions,
the walk’s budgets, and the typed homes for what applications used to put
in body_prefix: the route’s modulepreload links from the
build’s manifest, and head links. Never a nonce: the render draws one per
response. Data goes through PageConfig::config_json.
use forma_server::{HeadLink, PolicyExtensions, RenderCtx, WalkLimits};
let ctx = RenderCtx::new()
.with_policy(PolicyExtensions::new().img_src("https:"))
.with_limits(WalkLimits { max_list_iterations: 100_000, ..WalkLimits::default() })
.with_head_link(HeadLink::new("icon", "/favicon.svg")?);Implementations§
Source§impl RenderCtx
impl RenderCtx
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Override the bound page’s document title for this request; escaped as text.
Sourcepub fn with_body_class(self, class: impl Into<String>) -> Self
pub fn with_body_class(self, class: impl Into<String>) -> Self
Set this request’s body class; escaped as an attribute.
Sourcepub fn with_config_json(self, value: Value) -> Self
pub fn with_config_json(self, value: Value) -> Self
Request data assigned to window.__FORMA_CONFIG__ by a nonced script.
Static SSR routes refuse this executable configuration with RENDER-105.
Sourcepub fn with_personality_css(self, css: impl Into<String>) -> Self
pub fn with_personality_css(self, css: impl Into<String>) -> Self
Request branding CSS. The document writer neutralizes style end tags.
Sourcepub fn with_body_prefix(self, html: RawHtml) -> Self
pub fn with_body_prefix(self, html: RawHtml) -> Self
Explicit trusted markup before the page root; plain strings do not satisfy this API.
Sourcepub fn with_policy(self, policy: PolicyExtensions) -> Self
pub fn with_policy(self, policy: PolicyExtensions) -> Self
Extend this page’s policy (see PolicyExtensions).
Sourcepub fn with_limits(self, limits: WalkLimits) -> Self
pub fn with_limits(self, limits: WalkLimits) -> Self
Override both walk budgets for this request only. Without this call,
the handle’s bind-time limits apply. Use its limits() value with struct
update syntax to change just one budget.
Sourcepub fn with_module_preloads(self, preloads: &ModulePreloads) -> Self
pub fn with_module_preloads(self, preloads: &ModulePreloads) -> Self
Write the route’s modulepreload links from the build’s manifest,
each with the page’s nonce, after the route’s own modules. The
typed home for a preload workaround in body_prefix, such as
Ledger’s. The table covers every route; the render takes
config.route_pattern’s list. Like every typed home, each call site
belongs on the application’s raw-entry allowlist (forma-raw-lint).
use forma_server::{assets, ModulePreloads, RenderCtx};
// At start, beside the manifest; refuse to start on its error.
fn start<Assets: rust_embed::Embed>() -> Result<ModulePreloads, String> {
assets::try_load_module_preloads::<Assets>()
}
// Per request.
fn ctx(preloads: &ModulePreloads) -> RenderCtx {
RenderCtx::new().with_module_preloads(preloads)
}Verified by: crates/forma-server/tests/internal_renderer/typed_homes.rs > “try_render_writes_the_routes_manifest_modulepreload_links_nonced”
Sourcepub fn with_head_link(self, link: HeadLink) -> Self
pub fn with_head_link(self, link: HeadLink) -> Self
Add a <link> to the page’s head (see HeadLink), after any added
before it. The typed home for links spliced in before </head>; each
call site belongs on the application’s raw-entry allowlist
(forma-raw-lint).
Verified by: crates/forma-server/tests/internal_renderer/typed_homes.rs > “head_links_are_written_escaped_in_the_head_in_the_order_added”