Skip to content

Lifecycle ​

Interact constructs a fresh island for every request. Declared props and state are restored between requests; services and protected properties remain local to the current instance.

Initial render ​

  1. Resolve the island name and construct the island through CakePHP's container.
  2. Assign mount props and decode declared URL-bound state.
  3. Call authorize(IslandContext $context).
  4. Call mount().
  5. Call viewData() and render its native element or template.

Update ​

  1. Verify the signed snapshot, session, scope, and expiry.
  2. Construct a fresh island and restore its declared properties.
  3. Validate and apply browser edits and validate action argument types.
  4. Call authorize().
  5. Call updated() for changed fields, then the requested action.
  6. Return a requested redirect, or return accepted state, errors, events, and any download request. Call viewData() and render unless a successful action skips rendering.

The original controller action, layout, and mount() do not run again. Authorization can observe accepted edits and runs before application update hooks, actions, and rendering.

authorize() ​

php
public function authorize(IslandContext $context): void

Override this hook for current resource access checks on both mounts and updates. Import Interact\IslandContext. The request is available as $context->request. Throw the application's appropriate HTTP exception when access is denied. Public islands can use the default implementation. Action arguments referring to other resources need authorization in the action too.

mount() ​

php
public function mount(): void

Initialize state from props or load initial editable values. This hook runs on the first render only, so it does not replace a draft on later updates.

updated() ​

php
public function updated(array $paths): void

Receives accepted writable paths after authorization and before the action. Ordinary updates report changed paths. Use it to clear dependent fields or reset pagination. History restoration supplies the complete URL-property set, including unchanged values; see URL state. Successful file staging also invokes it for the affected top-level field.

php
/**
 * Clear a city that may no longer belong to the selected country.
 *
 * @param list<string> $paths Changed writable paths.
 */
public function updated(array $paths): void
{
    if (in_array('country', $paths, true)) {
        $this->cityId = null;
    }
}

This fragment assumes writable country and cityId properties. See the dependent fields example.

viewData() ​

php
public function viewData(): array

Return PHP-only template variables for the current render. The Properties page documents value visibility and naming.

Rendering and disposal ​

The browser applies returned HTML while preserving newer drafts, focus, local Alpine state, and matching nested islands. Removing an island releases its browser resources. See Requests and DOM updates.

A successful action redirect skips view data and rendering. Renderless actions also skip view data and rendering while returning accepted state and events. Validation errors force a render, and the next successful action renders again to clear that feedback. Downloads accompany an accepted rendered or renderless response. Both helpers are restricted to declared actions; see redirects and downloads.

Deferred initialization ​

Lazy loading authorizes the initial placeholder without running mount() or rendering island content. Initialization constructs a fresh instance and authorizes again before mounting. Normal updates then follow the lifecycle above.