Astro islands architecture

From Intense-Visions/harness-engineering · View interactive version

Astro islands architecture is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Ship zero JavaScript by default — hydrate only the interactive components that need it, exactly when they need it.

How to use this skill

Skill file

Astro Islands Architecture

Ship zero JavaScript by default — hydrate only the interactive components that need it, exactly when they need it.

When to Use

Instructions

  1. Default to .astro components for all non-interactive UI. They render to pure HTML with zero JS shipped to the browser.
  1. Use framework components (React, Vue, Svelte, etc.) only when client-side interactivity is required (event handlers, stateful UI, browser APIs).
  1. Apply a client:* directive to every framework component that must hydrate. Without a directive, the component renders as static HTML only.
  1. Choose the directive that matches when the component becomes interactive:
  1. Never use client:load as a default for all interactive components. Prefer client:idle or client:visible whenever the component is not immediately visible.
  1. Pass data into islands via props. Islands are isolated — they do not share state automatically.
---
// src/pages/index.astro
import StaticHeader from '../components/StaticHeader.astro';
import Counter from '../components/Counter.jsx';
import HeavyChart from '../components/HeavyChart.jsx';
import MobileMenu from '../components/MobileMenu.jsx';
---

<!-- Zero JS: pure static HTML -->
<StaticHeader />

<!-- Critical interactive: hydrate immediately -->
<Counter client:load initialCount={0} />

<!-- Below the fold: hydrate when visible -->
<HeavyChart client:visible data={chartData} />

<!-- Mobile only: skip on desktop entirely -->
<MobileMenu client:media="(max-width: 768px)" />
  1. Audit your islands by running the build and inspecting the dist/ output. Each client:* directive produces a separate JS chunk. Large chunks indicate over-hydration.
  1. Use transition:persist from the View Transitions API to keep an island alive across page navigations — avoiding a re-hydration cost.

Details

Islands Architecture was coined by Katie Sylor-Miller and popularized by Jason Miller. The central idea: treat the page as a sea of static HTML with interactive "islands" embedded within it. Each island is an independently hydrated component — its JavaScript is fetched and executed only for that component, not for the whole page.

Why this matters: A traditional SPA ships a full JavaScript bundle and hydrates the entire page. Astro's island approach means a content-heavy page (blog post, marketing landing page, documentation) ships zero JavaScript unless you explicitly add client:* to a component. This dramatically improves Time to Interactive (TTI) and Largest Contentful Paint (LCP).

How hydration works under the hood:

Astro serializes the component's props into the HTML at build time. When the browser loads the page, Astro's tiny runtime reads the directive, waits for the right moment (load, idle, visible, media match), then dynamically imports the component's framework bundle and hydrates it with the serialized props. Each island is fully independent.

Trade-offs:

Island communication patterns:

Partial hydration vs. progressive enhancement:

Islands Architecture is a form of partial hydration — you hydrate parts of the page, not all of it. This differs from progressive enhancement, which starts with fully functional HTML and layers JS on top. In practice, combine both: your .astro components are always progressive-enhancement-friendly, and your islands add richer interactivity.

Source

https://docs.astro.build/en/concepts/islands

Process

  1. Read the instructions and examples in this document.
  2. Apply the patterns to your implementation, adapting to your specific context.
  3. Verify your implementation against the details and edge cases listed above.

Harness Integration

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.