Skip to content

Vue islands

Astro renders Vue components to HTML on the server and hydrates only the ones you mark with a client:* directive. Nyxwire’s Vue components work both ways: without a directive they ship as static HTML, and as islands they become interactive.

Relay console

nocturne
Signal gain60%

Broadcasting on uplink at 60% gain

The console above is a Vue island on this Starlight page: a switch, a slider and a radio group from @nyxwire/vue, plus useFlavor reporting the flavor in use. Switch the flavor in the header and it follows; turn the broadcast off and the other controls are disabled.

  1. Add Vue, the Astro renderer, the components and Tailwind.

    Terminal window
    pnpm add @astrojs/vue vue @nyxwire/astro @nyxwire/vue @nyxwire/tailwind @nyxwire/css
    pnpm add -D tailwindcss @tailwindcss/vite
  2. Register the Vue renderer and the Tailwind Vite plugin next to the integration. Tailwind brings the theme, so the integration imports no CSS.

    astro.config.mjs
    import { defineConfig } from 'astro/config'
    import vue from '@astrojs/vue'
    import tailwindcss from '@tailwindcss/vite'
    import nyxwire from '@nyxwire/astro'
    export default defineConfig({
    integrations: [vue(), nyxwire({ styles: false })],
    vite: { plugins: [tailwindcss()] },
    })
  3. Create the global stylesheet and import it in your layout.

    src/styles/global.css
    @import 'tailwindcss';
    @import '@nyxwire/tailwind';
    @import '@nyxwire/vue/tailwind.css';

    The last line makes Tailwind scan the components’ build, so the classes they use are generated.

On a Starlight site, keep the Starlight stylesheet instead and add only vue() to the integrations.

Each island is its own Vue app, so wrap its content in NwProvider: it supplies the Reka UI config (direction, locale and SSR-stable ids), the tooltip and toast providers, and the flavor scope. This is the console above, src/components/guides/RelayConsole.vue in this site:

src/components/guides/RelayConsole.vue
<script setup lang="ts">
// Island demo for the Vue islands page, which shows this file's source verbatim.
import { computed, ref } from 'vue'
import {
NwLabel,
NwProvider,
NwRadioGroup,
NwRadioGroupItem,
NwSlider,
NwSwitch,
useFlavor,
} from '@nyxwire/vue'
const broadcasting = ref(true)
const gain = ref([60])
const band = ref('uplink')
const bands = [
{ value: 'uplink', label: 'Uplink' },
{ value: 'mesh', label: 'Mesh' },
{ value: 'backhaul', label: 'Backhaul' },
]
const { resolvedFlavor } = useFlavor()
const status = computed(() =>
broadcasting.value ? `Broadcasting on ${band.value} at ${gain.value[0]}% gain` : 'Relay idle',
)
</script>
<template>
<NwProvider>
<div class="grid w-full max-w-sm gap-5 rounded-lg border border-line bg-panel p-5 shadow-sm">
<div class="flex items-center justify-between gap-4">
<p class="m-0 font-display text-lg font-semibold text-fg">Relay console</p>
<span class="font-mono text-2xs tracking-wide text-fg-subtle uppercase">
{{ resolvedFlavor }}
</span>
</div>
<NwSwitch v-model="broadcasting" label="Broadcast" />
<div class="grid gap-3">
<div class="flex items-center justify-between gap-4">
<NwLabel as="span">Signal gain</NwLabel>
<span class="font-mono text-xs text-fg-muted">{{ gain[0] }}%</span>
</div>
<!-- The thumb is the focusable control, so it carries the accessible name. -->
<NwSlider
v-model="gain"
:max="100"
:step="5"
:disabled="!broadcasting"
:thumb-labels="['Signal gain']"
/>
</div>
<NwRadioGroup v-model="band" label="Band" :disabled="!broadcasting">
<NwRadioGroupItem v-for="item in bands" :key="item.value" :value="item.value">
{{ item.label }}
</NwRadioGroupItem>
</NwRadioGroup>
<p class="m-0 font-mono text-xs text-fg-muted" role="status" data-relay-status>
{{ status }}
</p>
</div>
</NwProvider>
</template>

Then render it with a directive:

src/pages/relays.astro
---
import RelayConsole from '../components/RelayConsole.vue'
---
<RelayConsole client:visible />
Directive Hydrates Use for
none never: static HTML Components that only display
client:visible when it scrolls into view Most interactive components
client:idle when the browser is idle Below-the-fold widgets that should be ready soon
client:load immediately Controls the visitor uses first, above the fold

Islands do not share Vue state. Pass data through props, or keep shared state outside Vue, such as the flavor runtime.

The flavor runtime from the integration (or the Starlight plugin) owns <html>. Inside an island, useFlavor detects window.nyxwire, delegates setFlavor to it, and listens to nyxwire:flavor, so every island and the page’s own selectors agree. The head script applies the flavor before islands hydrate, so nothing flashes. Without a page runtime, useFlavor stores the preference under the same nyxwire-flavor key and sets the attributes on <html> itself.

To pin one island to a flavor or an accent, pass it to the provider: <NwProvider flavor="abyss" accent="volt"> wraps the content in a data-flavor and data-accent scope. NwFlavorSelect inside the island edits that scope through v-model:

<script setup lang="ts">
import { ref } from 'vue'
import type { FlavorName } from '@nyxwire/vue'
import { NwFlavorSelect, NwProvider } from '@nyxwire/vue'
const flavor = ref<FlavorName>('abyss')
</script>
<template>
<NwProvider v-model:flavor="flavor">
<NwFlavorSelect v-model="flavor" label="Panel flavor" />
</NwProvider>
</template>

Nyxwire’s components are safe to render on the server: NwProvider hands Vue’s useId to Reka so ids match after hydration, and useFlavor reads nothing from window until the component mounts. Avoid client:only="vue" unless a component cannot render on the server; it removes the HTML until the script loads.