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 new() -> Self
pub fn new() -> Self
The strict policy and the walker’s default budgets (8 MiB of output, 50,000 list rows).
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
Budget this page’s walk differently from the defaults.
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/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/typed_homes.rs > “head_links_are_written_escaped_in_the_head_in_the_order_added”