livewire·rust

livewire 4 protocol · laravel rust

Reactive components.
Written in Rust.

Livewire shows its power in Laravel because the browser and the server agree on one contract: a snapshot in the HTML, an update endpoint, and a client that swaps what comes back. This crate implements that contract for Laravel Rust — typed components instead of PHP classes, Jinja templates instead of Blade, and the upstream JavaScript runtime exactly as it ships.

MIT Licence no PHP, no Node at runtime vendored browser client local hosting: laserstack live example: feature lab ↗ Source on GitHub ↗

01 · The shape of it

One protocol. Two languages.

The port keeps every wire detail the client depends on and changes only the server's authoring model. A page renders a snapshot; the browser posts updates; the server answers with HTML and effects.

1update endpoint, with the headers, ordering, and limits the client expects
HMACchecksum over every snapshot, plus release tokens and a failure rate limit
0Node processes on the server: the bundles are embedded and served from Rust
100%of upstream JavaScript reused, with its test suite in place

02 · What you write

Components as Rust types, views as Jinja.

Protocol and security

The snapshot {data, memo, checksum}, HMAC-SHA256 with the application key, release tokens, the checksum-failure allowance, and the four payload limits. A tampered body is 419, a flood is 429, and production leaks no message.

Components and lifecycle

#[derive(LivewireComponent)] builds the wire field table in declaration order; #[livewire::component] forwards the lifecycle and publishes actions, listeners, renderless, json, async, isolate, and computed.

Updates and actions

Dotted paths with __rm__ removal, missing-object creation, a depth guard, locked-field rejection, typed action parameters, and the internal $refresh, $set, and $commit calls.

Rendering

.livewire templates on MiniJinja with the framework's helpers, livewire:name, @this, @entangle, @assets, @script, @island, @teleport, @persist, morph markers, and root-tag injection that never reformats your markup.

Interactions and effects

Validation into memo.errors as the client indexes it, events, xjs/js, JSON returns, authorization answering 403, redirects, downloads, and streamed frames before the final payload.

Composition

Nesting with memo.children, slots as child fragments, reactive props answering {skip:true}, lazy and deferred placeholders, islands, per-component JS and CSS modules, single-file and module-and-view components.

Persistence

#[livewire(model)] with ModelRef<T> behind the database feature, fetched before render and 404 on a missing row; pagination over the framework's own paginator; computed properties memoized per request.

Pages and guards

A page component mounts from a route and records its path, method, and origin — whatever method rendered it. An update from another origin answers 404, and registered PersistentMiddleware guards run on every update the page drives.

Uploads and streams

Signed local uploads with previews and a configured throttle, the four upload actions with their dispatch events, the scheduled pruner, and streamed answers the unchanged client already reads.

Commands and testing

make:livewire with its five generation modes, livewire:config, :layout, :convert, :publish, :stubs, and the Testable harness that mounts, sets, calls, and asserts without HTTP.

The browser runtime

Upstream's runtime, vendored and built deterministically, with its Vitest suite intact. Normal, CSP, and minified bundles and their maps are served by the crate; inject_assets never doubles an explicit helper.

03 · Quickstart

From a route to a counter in four files.

This is the demo application in laravel-rust, reduced to the essentials.

// src/livewire/counter.rs
#[derive(Default, livewire::LivewireComponent)]
#[livewire(view = "livewire.counter")]
pub struct Counter {
    #[livewire(locked)]
    pub id: String,
    #[livewire(validate(required, max_length(255)))]
    pub step: String,
    pub count: u32,
}

#[livewire::component]
impl Counter {
    pub fn increment(&mut self) {
        self.count += 1;
    }
}
<!-- resources/views/livewire/counter.livewire -->
<div>
  <h1 wire:text="count"></h1>
  <button wire:click="increment">+1</button>
</div>
// src/app.rs — register the component with the provider
providers.add(LivewireServiceProvider::new(|components| {
    components.register::<Counter>("counter").expect("registered once");
}));

// src/routes/web.rs — serve a page
route.get("/livewire/counter", livewire::counter);

Then load the page and press the button. No JavaScript is written for it: the vendored client sends the update and swaps the HTML.

04 · Shortcomings

What 0.1.3 does not do.

Each row is a behaviour the source shows, not a missing test. The full account, with the proof for every other row, is STATUS.md in the repository.

GapConsequence
#[livewire(modelable)] is parsed, and memo.bindings is read but never writtena modelable child behaves as an ordinary child
The module endpoints exist, but no scriptModule or styleModule effect is emitteda render does not load a component's JavaScript or CSS module
component_layout and the layout/title options are inerta page component extends a layout in its own view
temporary_file_upload.disk and .cleanup are not readthe local disk and the application's schedule are the only behaviour
livewire:form has no generator herethe form struct is written by hand; the form object itself works
livewire:attribute has no generator herebehaviour is a macro, so there is no attribute class to write
S3 storage is absentno presigned uploads, and no bucket-lifecycle branch in the cleanup command
No Jinja @error or old-input helpersa template reads validation messages from memo.errors
Option<ModelRef<T>> and Vec<ModelRef<T>> are refused by the macroa nullable relation is a defaulted reference that reports None
Only max:<kilobytes> of the upload rules is readother rule strings are ignored by the upload endpoint
The fixtures cite the pinned PHP sources; no PHP application was executedprotocol shapes are verified against source text, not against an oracle

05 · Toward parity

What comes next, in order.

The remaining work for a complete 4.x port. Nothing here is a redesign; each item closes a gap the table above names.

  1. livewire:form — write the struct an #[livewire(form)] field expects.
  2. Module effects — emit scriptModule, childScriptModules, styleModule, and globalStyleModule.
  3. modelable — write memo.bindings and the binding directives, then partition parent and child updates.
  4. component_layout — wrap a page component that extends nothing.
  5. Upload settings — read disk and cleanup; add S3 presigning and the lifecycle branch.
  6. Template validation helpers — @error and old input in Jinja.
  7. A PHP oracle run — regenerate the protocol fixtures from the pinned application, if its dependencies install.
  8. Nullable model references — hydrate Option<ModelRef<T>> and Vec<ModelRef<T>>.

06 · By design

What will never match PHP.

These are not gaps to close later. Rust is not PHP, and pretending otherwise would produce a second, worse framework.

DifferenceWhy it is inherentWhat you see
A component is a typeno reflection, and the wire never names a class to instantiatethe field's Rust type is the allowlist; an unknown type is 419 or 422 where PHP answers 500
Behaviour is a macroRust attributes are compile-time; there is no runtime attribute registry#[livewire(..)] and #[component] replace Livewire\Attributes\* classes
Views are Jinjathe framework ships no Blade engine{% if %} and {% for %}, morph markers from the preprocessor, no @php and no Blade components
No container injection into actionsthe framework injects handler parameters, not action bodiesservices arrive as action parameters or are resolved explicitly
Snapshots are runtime-specifica Rust snapshot cannot be driven by PHP, nor the reversethe envelope, checksum, and client contract match; the state does not cross runtimes
State is request-localstatics and weak maps are PHP constructs; concurrency is Tokio'snothing is process-global, so parallel requests cannot leak into each other
Maintenance is Rustthere is no PHP console file for a command to editupload cleanup is a with_schedule task in the application, not a generated entry
Commands generate Rustthe authoring unit is a module, not a classmake:livewire writes src/livewire/*.rs plus .livewire views, with the same names, options, and conflict rules

The record these sections summarise is in STATUS.md and the 0.1.3 release notes.