Skip to content

Islands Demo

A theme section that visualizes island hydration in real time. Each card transitions from "Waiting" to "Hydrated" with timestamps, so you can see exactly when each directive fires.

Components

Nine islands demonstrate each directive:

ComponentDirectiveTrigger
island-demo-idleclient:idlerequestIdleCallback (500ms timeout)
island-demo-visibleclient:visibleIntersectionObserver (200px rootMargin)
island-demo-mediaclient:media="(min-width: 768px)"Desktop viewport
island-demo-media-mobileclient:media="(max-width: 767px)"Mobile viewport
island-demo-deferclient:defersetTimeout (2s)
island-demo-interactionclient:interactionmouseenter, touchstart, focusin
island-demo-parentclient:idleParent in nested demo
island-demo-childclient:visibleChild in nested demo

How it works

Each island calls a shared hydrate() function from frontend/lib/island-demo.js that updates the card's class, timestamp, and status.

Unique tag names

The hydration runtime tracks islands per tag name, not per element. Each demo card uses a unique tag so directives run independently.

Nested islands

The child is invisible until the parent hydrates. Once the parent renders, the runtime re-walks its subtree and discovers the child. Timestamps show the timing cascade.

Event log

The section captures islands:load events. Each event includes:

js
{
  tag: 'island-demo-idle',  // Custom element tag name
  duration: 12,             // Hydration time in ms
  attempt: 1                // Import attempt (1 = first try)
}

A classic <script> tag (non-module) registers listeners before ES modules execute, so no events are missed.

Add the demo to your store

The section is included in the homepage template. Add it to any page through the theme editor. The schema supports a customizable heading:

json
{
  "name": "t:sections.islands_demo.name",
  "settings": [
    {
      "type": "text",
      "id": "heading",
      "label": "t:sections.islands_demo.settings.heading.label"
    }
  ]
}

Source files

FilePurpose
theme/sections/islands-demo.liquidSection template
theme/frontend/lib/island-demo.jsShared hydration helper
theme/frontend/islands/island-demo-*.jsIndividual demo islands

Next steps