Skip to content

vs Livewire ​

Livewire was the most direct reference when the PHP version was designed, and the Rust starter inherits the same answers. Both let you write only the back end and still get interaction, but they answer "state" and "exposed surface" differently.

The core differences ​

LivewireLinker (Rust)
StateRound-trips with each request (snapshot + signature check)Only on the server (serialized into the cache); the browser gets uuid + rev
Exposed surfaceA component's public methods and propertiesOnly the methods in METHODS; struct fields are never sent to the browser
ArgumentsMethod arguments + bound propertiescall receives the whole args map; you pick the keys you need and validate them
ReturnsRe-rendered component HTML, morphed into the DOMdata + named actions; for HTML, use Action::render_fragment
Server telling the browser$this->js(), dispatched eventsThe action table (ui.toast, render.fragment…), no arbitrary JS
ErrorsValidation errors built in; the rest customFixed kinds, one handler in the browser
Bindingwire:model binds both ways to server propertiesdata-state-bind binds to client state; the server receives values only when you call it
LanguagePHPRust; field types checked by the compiler

The same feature written both ways ​

Livewire style ​

php
class TicketWizard extends Component
{
    public int $step = 1;
    public string $subject = '';

    public function next()
    {
        $this->validate(['subject' => 'required|max:120']);
        $this->step = 2;
    }
}
blade
<input wire:model="subject">
<button wire:click="next">Next</button>
@if ($step === 2) … @endif

Linker style ​

rust
#[derive(Default, Serialize, Deserialize)]
pub struct TicketWizard {
    step: u8,
    subject: String,
}

impl LinkerComponent for TicketWizard {
    const ALIAS: &'static str = "ticketWizard";
    const METHODS: &'static [&'static str] = &["saveSubject"];

    async fn mount(&mut self, _: &LinkerContext, _: &Args) -> laravel::Result<()> {
        self.step = 1;
        Ok(())
    }

    async fn call(&mut self, _: &LinkerContext, method: &str, args: Args) -> laravel::Result<LinkerResponse> {
        match method {
            "saveSubject" => {
                let subject = args.get("subject").and_then(Value::as_str).unwrap_or_default().trim();
                if subject.is_empty() || subject.chars().count() > 120 {
                    return Ok(LinkerResponse::validation([("subject", "A subject is required, at most 120 characters.")]));
                }
                self.subject = subject.to_owned();
                self.step = 2;
                Ok(LinkerResponse::ok().data("step", self.step))
            }
            _ => unreachable!("METHODS lists every method"),
        }
    }
}
html
<div{{ wizard_attrs }} data-state-init="step=1">
    <form data-state-is="step=1">
        <input name="subject" data-state-bind="subject">
        {{ cg_button("Next", type="submit", attrs={"data-linker-call": "saveSubject", "data-linker-args": "form"}) }}
    </form>
    <div data-state-is="step=2">…</div>
</div>

wizard_attrs is the linker::mount::<TicketWizard, User> mount attributes plus the render object attributes, built by the handler. The full version is in the multi-step wizard tutorial.

What the differences mean ​

Where Linker is safer

  • step isn't in the browser. There's no need to "lock properties" or sign anything against tampering: the thing to tamper with doesn't exist.
  • Adding a pub fn doesn't accidentally create an endpoint; forgetting to add it to METHODS means "the feature doesn't work" (policy).
  • There's no eval path, so CSP doesn't need unsafe-eval.

Where Livewire is more convenient

  • Ecosystem, documentation, community, third-party components.
  • Server properties are template variables directly; no need to separate "server state" from "client display values".
  • Morphing keeps as much DOM as possible, so you don't have to think about fragment sizes.
  • Declarative validation; the Rust version writes validation by hand in every method.

Trade-offs

  • Stateful instances are stored in the cache; several machines need a shared Redis (or database cache store).
  • Instances disappear on reload. To let users resume, save a DB draft.
  • After changing a state struct's fields, old instances fail to deserialize and return expired, and the user just reloads. Know this when you deploy.