Mount
Auto-discovers all [data-ilha] elements in the DOM and mounts the matching island from a registry. This is the recommended way to activate islands on a page, especially when using SSR and hydration.
Basic usage
Each key in the registry maps to a data-ilha attribute value in the HTML:
Options
Unmounting
mount() returns an object with an unmount function that tears down all discovered islands at once:
Lazy mounting
When lazy: true is set, islands are not mounted immediately. Instead, each host element is observed with an IntersectionObserver and mounted only when it enters the viewport. This keeps the initial page load lean when islands are below the fold.
Once an island becomes visible it mounts normally and is no longer observed.
Passing props
Props can be embedded directly in the HTML using data-ilha-props. mount() reads and parses this attribute automatically — no need to pass props through JavaScript:
Hydration with state snapshots
When using .hydratable() on the server, the rendered HTML includes a data-ilha-state attribute with a snapshot of signal values. mount() reads this automatically and restores state without re-fetching or re-computing:
See .hydratable() for how to generate this output on the server.
Scoping to a subtree
Pass a root element to limit discovery to a specific part of the page. This is useful when islands are injected dynamically into a container:
Notes
- If a
data-ilhavalue has no matching key in the registry, that element is silently skipped. - In dev mode, double-mounting the same element logs a warning and returns a no-op for that element.
mount()is safe to call before the DOM is fully loaded if you wrap it in aDOMContentLoadedlistener or place the script at the end of<body>.