Skip to content

HandleRequests

Magewire specific (since: 3.0.0)

HandleRequests (sort order 1200) is the entry point for subsequent requests: the /magewire/update XHR that fires when a user interacts with a component. It receives the POST, drives HandleComponents for each component in the payload, and assembles the JSON response.

On an initial page render this mechanism does nothing; the work happens only on update roundtrips.

The update flow

A Magewire update is a single POST carrying one or more component payloads. handleUpdate() walks them:

  1. Parse the request envelope, verify the form key, and create a request context.
  2. Run registered request filters once, in DI order. A rejection stops before reconstruction.
  3. Fire the request event.
  4. For each component payload:
  5. magewire:component:reconstruct: rebuild the block and component from the snapshot (via its resolver).
  6. Mark the component as updating: store($component)->set('magewire:update', $payload).
  7. Render the block ($block->toHtml()), which runs the component lifecycle through HandleComponents.
  8. Collect the new snapshot and effects.
  9. Fire the response event and return the assembled payload:
{
  "components": [
    { "snapshot": "…serialized snapshot…", "effects": { "…": "…" } }
  ],
  "assets": []
}

The browser runtime takes each component's new snapshot and effects, morphs the DOM, and applies the effects (redirects, dispatched events, flash messages, …).

Identifying a Magewire request

$handleRequests->isMagewireRequest(); // true on a /magewire/update XHR

Internally this just asks the runtime whether the mode is SUBSEQUENT, using it as the single source of truth for "are we on an update request?".

Routing is Magento's, not Livewire's

The ported Livewire class still carries Laravel route helpers (findUpdateRoute(), route macros). In Magewire those are Portman leftovers: the actual endpoint is wired through a Magento controller (MagewireUpdateRoute), which boots the runtime in SUBSEQUENT mode and hands off to this mechanism. The update URI is exposed to templates via utils()->magewire()->getUpdateUri() (see View Model & Utilities).