Skip to main content

RenderCtx

Struct RenderCtx 

Source
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

Source

pub fn new() -> Self

The strict policy with limits inherited from the bound page.

Source

pub fn with_title(self, title: impl Into<String>) -> Self

Override the bound page’s document title for this request; escaped as text.

Source

pub fn with_body_class(self, class: impl Into<String>) -> Self

Set this request’s body class; escaped as an attribute.

Source

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.

Source

pub fn with_personality_css(self, css: impl Into<String>) -> Self

Request branding CSS. The document writer neutralizes style end tags.

Source

pub fn with_body_prefix(self, html: RawHtml) -> Self

Explicit trusted markup before the page root; plain strings do not satisfy this API.

Source

pub fn with_policy(self, policy: PolicyExtensions) -> Self

Extend this page’s policy (see PolicyExtensions).

Source

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.

Source

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”

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”

Trait Implementations§

Source§

impl Clone for RenderCtx

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RenderCtx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RenderCtx

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more