MARY.WIN

RUSTY — INERTIA — CHAPTER 06

When a Prop
Is Sent

Chapter 6 of 10 in Inertia on Rust, draft chapters on the Inertia adapter for Rust.

Every prop so far was computed in the handler and sent on every visit. In this chapter we'll look at four ways to change that: props sent only when asked for, props fetched after the first render, props the client keeps, and how a partial reload chooses among them.

This chapter assumes Chapter 5. It does not cover merge props beyond a mention, or live and broadcast props.

Four loading modes

The handler believed every prop was wanted. It loaded the audit trail on each visit and handed it over with the invoices. The component put the audit trail behind a tab. Most visits ended without the tab being opened.

Sometimes a prop is slow to compute and seldom looked at. Thankfully, a prop can be a callback that runs only when the response includes it. Take a look at Example 6-1.

Example 6-1. Four props, four schedules

pub async fn index(inertia: Inertia) -> inertia::Response {
    inertia.render(
        "Invoices/Index",
        props! {
            "invoices" => ["INV-7", "INV-8"],
            "audit" => inertia::optional(|| async { ["created", "sent"] }),
            "totals" => inertia::defer(|| async { 2400 }),
            "plans" => inertia::once(|| async { ["basic", "pro"] }),
        },
    )
}

Let's walk through the four. invoices is a plain value and is sent on every full visit. optional wraps a callback that is sent only when a partial reload asks for it. defer leaves the prop out of the first render and tells the client to fetch it right after. once is resolved once, and the client remembers it on later visits.

Example 6-2 is the first visit.

Example 6-2. The first visit

{"component":"Invoices/Index",
 "props":{"errors":{},"app_name":"Ledger","auth":{"user":"Mary"},
          "invoices":["INV-7","INV-8"],"plans":["basic","pro"]},
 "url":"/invoices","version":"1",
 "sharedProps":["errors","app_name","auth"],
 "deferredProps":{"default":["totals"]},
 "onceProps":{"plans":{"prop":"plans","expiresAt":null}}}

As you can see, audit and totals are absent from props. totals is listed under deferredProps, in a group named default, which is how the client knows to come back for it. plans is present and also listed under onceProps.

Partial reloads

A partial reload is an ordinary Inertia visit with two more headers: one naming the component and one naming the props it wants (see Example 6-3).

Example 6-3. Asking for one prop

let request = visit("GET", "/invoices")
    .header("x-inertia-partial-component", "Invoices/Index")
    .header("x-inertia-partial-data", "audit")
    .body(Body::empty())
    .unwrap();

The reply's props hold errors and audit and nothing else. The callbacks for totals and plans did not run, and the shared props app_name and auth were not sent either.

You can also mark a prop always, which sends it with every response, including partial reloads that didn't name it. If you're unsure whether a shared prop needs that, I'd check what your layout reads after a partial reload before adding it.

You can also put deferred props in named groups with .group("name"), so the client fetches the props of a group together.

What this chapter leaves open

So the audit trail is no longer loaded for visits that never look at it. Deferring totals is a different trade: the page arrives sooner and the server answers twice. Is the second request cheaper than the wait it replaced? How would you find out for your slowest prop, and have you?

Testing

Example 6-4 fails if an optional or deferred prop leaks into a first visit.

Example 6-4. What a first visit must not carry

AssertablePage::from_body(&reply.body)
    .has_count("invoices", 2)
    .missing("audit")
    .missing("totals")
    .has("plans")
    .deferred("default", &["totals"]);

TL;DR

optional props are sent only to a partial reload that names them. defer props are left out of the first render and listed in deferredProps for the client to fetch. once props are sent, listed in onceProps, and skipped when the client says it already has them. A partial reload sends the named props and errors; always overrides that for a prop.

The sources.

Each line is a claim this chapter makes and where to look. Checked on 2026-11-29 against inertia-laravel-rust at commit 3ccc126.

CLAIM × WHERE — 9
  • A lazy prop's callback runs only when the prop is part of the response, after the handler returnsR1 · src/props/mod.rs L262-L288
  • optional: only sent when a partial reload asks for itR1 · src/props/mod.rs L316-L324; src/props/prop.rs L144-L148
  • defer: left out of the first render, fetched right after, in the default group; group() names anotherR1 · src/props/mod.rs L326-L335; src/props/prop.rs L150-L160
  • once: resolved once and remembered by the clientR1 · src/props/mod.rs L337-L345; src/props/prop.rs L223-L227
  • always: sent with every response including partial reloads that did not askR1 · src/props/mod.rs L347-L351; src/props/prop.rs L169-L174
  • Partial reload headers: x-inertia-partial-component and x-inertia-partial-data; once exclusion header x-inertia-except-once-propsR1 · src/header.rs L17-L21, L35-L36
  • A partial reload naming one prop returns errors and that prop; shared props app_name and auth are not sentrun · test output a_partial_reload_gets_what_it_names
  • First visit lists totals under deferredProps.default and plans under oncePropsrun · test output a_first_visit_leaves_out_optional_and_deferred_props
  • AssertablePage::deferred asserts the deferred props of a groupR1 · src/testing.rs L425-L438

R1: inertiajs/inertia-laravel-rust @3ccc126a24c8fb5bddb140876a1825292c0d216c
run: Observed by running the chapter listings on 2026-11-29; the code that produces it was not read