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
- Resolve the island name and construct the island through CakePHP's container.
- Assign mount props and decode declared URL-bound state.
- Call
authorize(IslandContext $context). - Call
mount(). - Call
viewData()and render its native element or template.
Update
- Verify the signed snapshot, session, scope, and expiry.
- Construct a fresh island and restore its declared properties.
- Validate and apply browser edits and validate action argument types.
- Call
authorize(). - Call
updated()for changed fields, then the requested action. - 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()
public function authorize(IslandContext $context): voidOverride 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()
public function mount(): voidInitialize 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()
public function updated(array $paths): voidReceives 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.
/**
* 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()
public function viewData(): arrayReturn 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.