MARY.WIN

RUSTY — INERTIA — CHAPTER 07

Redirects
and Versions

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

An Inertia client follows redirects with fetch, and fetch does not behave like a browser's address bar. In this chapter we'll look at the adjustments the crate makes to responses on your behalf, and the one setting that makes the first of them possible: the asset version.

This chapter assumes Chapter 3. It does not cover prefetching, and it mentions history encryption without exercising it.

The stale tab

The browser tab had been open since Tuesday and held Tuesday's JavaScript. On Thursday it asked for the next page as if nothing had happened. The server compared two version strings, found its own 1 against the tab's 0, and answered 409.

Sometimes you deploy new assets while people have the old ones loaded. Thankfully, the version check handles that before your handler runs. Take a look at Example 7-1.

Example 7-1. Setting the version

Config::new().version("1")

There is one piece here. Every Inertia GET visit carries the client's version in a header. When it differs from the server's, the crate replies 409 Conflict with an X-Inertia-Location header holding the full URL, and the client makes a full page load to pick up the new assets. Only GET visits are checked.

You can also compute the version on every request with Config::version_with, for example from a hash of the build manifest.

What happens to your redirects

Example 7-2 is four handlers that each return something ordinary.

Example 7-2. Four ordinary responses

pub async fn archive() -> Response {
    inertia::redirect("/invoices").into_response()
}

pub async fn jump() -> Response {
    inertia::redirect("/invoices#latest").into_response()
}

pub async fn billing_portal(inertia: Inertia) -> Response {
    inertia.location("https://billing.example.com/portal").into_response()
}

pub async fn touch() -> StatusCode {
    StatusCode::OK
}

Here is what an Inertia client receives from each.

Handler Request Reply
archive PUT 303 See Other, Location: /invoices
jump POST 409 Conflict, X-Inertia-Redirect: /invoices#latest
billing_portal GET 409 Conflict, X-Inertia-Location: https://billing.example.com/portal
touch PUT, with a Referer 303 See Other, Location set to the Referer

inertia::redirect produces a 302. After a PUT, PATCH, DELETE or QUERY visit the crate turns that into a 303, so the browser follows it with a GET. A redirect whose URL has a fragment becomes a 409, because fetch drops fragments when it follows a redirect. inertia.location is for a URL the client should load in full, such as another site. An empty 200 becomes a redirect back.

For a request that is not an Inertia visit, none of this applies, and the response only gains a Vary: X-Inertia header.

You can also encrypt a page in the browser's history with encrypt_history, on the configuration or per request, and clear the history on the next page with clear_history. This chapter did not run either.

What this chapter leaves open

So a stale tab is caught, provided the version string changes when the assets do. The example sets it to "1". Who changes it to "2"? Is that a step in your deploy, or a line someone edits? What does a customer see on the day it is forgotten?

Testing

Example 7-3 sends a visit with an old version and fails unless the reply is a 409 with the full URL.

Example 7-3. An outdated client

let request = http::Request::builder()
    .uri("/invoices")
    .header("host", "localhost")
    .header("x-inertia", "true")
    .header("x-inertia-version", "0")
    .body(Body::empty())
    .unwrap();
let reply = send(&app(), request).await;

assert_eq!(reply.status, StatusCode::CONFLICT);
assert_eq!(reply.header("x-inertia-location"), Some("http://localhost/invoices"));

TL;DR

The asset version is compared on every Inertia GET visit, and a mismatch gets a 409 that makes the client reload in full. Redirects after PUT, PATCH, DELETE and QUERY become 303. Redirects with a fragment and calls to location become 409 with a header the client acts on. An empty 200 becomes a redirect back.

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
  • Version check runs ahead of the handler for Inertia GET visits only; mismatch returns 409 with X-Inertia-Location holding the full URLR1 · src/protocol.rs L13-L34; src/axum/layer.rs L103-L105
  • Config::version sets a fixed version; version_with computes it per requestR1 · src/config.rs L63-L75
  • inertia::redirect produces a 302R1 · src/protocol.rs L75-L83
  • A 302 after PUT, PATCH, DELETE or QUERY becomes 303R1 · src/protocol.rs L36-L41, L99-L103
  • A redirect to a URL with a fragment becomes 409 with X-Inertia-Redirect, because fetch drops fragmentsR1 · src/protocol.rs L42-L43, L61-L70
  • location: 409 with X-Inertia-Location for Inertia visits, a plain redirect otherwiseR1 · src/protocol.rs L85-L97; src/inertia.rs L182-L187
  • An empty 200 on an Inertia visit becomes a redirect backR1 · src/protocol.rs L39, L53-L57
  • Non-Inertia requests only gain Vary: X-InertiaR1 · src/protocol.rs L47-L51, L109-L124, L227-L234
  • encrypt_history on Config and per request; clear_history on the next pageR1 · src/config.rs L123-L127; src/inertia.rs L151-L167

R1: inertiajs/inertia-laravel-rust @3ccc126a24c8fb5bddb140876a1825292c0d216c