This is the contents of the README on the GitHub repo.

SvelteKit + <is-land>

SvelteKit islands over an image of Outset Island from Zelda

This is an experiment with adding partial hydration to a SvelteKit site with @11ty/is-land, a “framework independent partial hydration islands architecture implementation.”

By using the provided Island.svelte component, you can selectively hydrate individual components instead of the whole page.

This is just a POC for now, but may be packaged for reuse at a later date.

Getting started

Create a component in /src/lib/islands. On your page, import the Island.svelte component and the component you would like to render inside the island.

For partial hydration to work, you need to disable client-side rendering for the page. Otherwise, the entire page will hydrate.

<script>
	import Count from '$lib/islands/Count.svelte';
	import Island from '$lib/Island.svelte';
</script>

<h2>Without props</h2>

<Island component={Count} name="Count" />

<h2>With props</h2>

<Island component={Count} name="Count" props={{ title: 'island' }} />

<h2>Customizing island options</h2>

<Island component={Count} name="Count" islandProps={{ 'on:interaction': true }} />

You will also need to set up a separate Vite build to bundle the island components - see the build script in this repo’s package.json for an example.

Props

See the source code for +page.svelte for a full example.

How it works

The bulk of the work is in /src/lib/Island.svelte. This component renders an <is-land> element with a <template data-island> that initializes the provided component using the client-side component API.

We have two build steps so we can import the island components indepently. First, we build the components in $lib/islands using Vite with islands.config.js, and then we build the SvelteKit app as normal. A separate entry point is generated for each island (e.g. /src/lib/islands/Count.svelte -> /static/__islands/Count.js). The islands are placed in the static/ folder so that it is deployed with the app. We can’t go through the normal SvelteKit build pipeline since when CSR is disabled, no client-side JS will load.

At dev time, no separate build step is required, since we can import Svelte components directly from /src/lib/islands and the Vite dev server will handle it.

Current limitations

These are the current limitations. If you have ideas on how to fix some of these, let me know!

Gotchas

Developing

Once you’ve created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.