Skip to content

Jeffallan/claude-skills / skills/vue-expert

vue-expert

Verified

Builds Vue 3 components with Composition API patterns, renders Vue on the server without Nuxt, sets up Pinia stores, scaffolds Quasar/Capacitor mobile apps, implements PWA features, and optimises Vite builds. Use when creating Vue 3 applications with Composition API, writing reusable composables, managing state with Pinia, building hybrid mobile apps with Quasar or Capacitor, configuring service workers, or tuning Vite configuration and TypeScript integration. For Nuxt projects, use nuxt-expert.

FileKindSize
SKILL.mdskill md4.4 KB
references/build-tooling.mdmarkdown9.4 KB
references/components.mdmarkdown8.8 KB
references/composition-api.mdmarkdown5.8 KB
references/mobile-hybrid.mdmarkdown13.5 KB
references/ssr.mdmarkdown4.3 KB
references/state-management.mdmarkdown9.6 KB
references/typescript.mdmarkdown10.7 KB

references/ssr.md

View on GitHub
# Vue SSR Without Nuxt

Server-side rendering with Vue's own APIs (`createSSRApp`, `renderToString`) and a Node server you control. For Nuxt projects (`nuxt.config.ts`, `useFetch`, server routes, route rules, islands, Nuxt 4 upgrades), use the `nuxt-expert` skill instead: Nuxt handles payload transfer, hydration and rendering modes for you.

## When to Use

- An existing Vite + Vue app needs SSR and adopting Nuxt is not an option
- Embedding server-rendered Vue in another Node server (Fastify, Express)
- Understanding or fixing hydration mismatches in any Vue SSR setup

## When Not to Use

- Any Nuxt project: `nuxt-expert`
- Static marketing sites: prerender with Nuxt or VitePress rather than hand-rolled SSR

## Custom SSR with Fastify

For custom Vue 3 SSR without Nuxt, using Fastify as the server:

```typescript
// server.ts
import Fastify from 'fastify'
import { createSSRApp } from 'vue'
import { renderToString } from 'vue/server-renderer'
import App from './App.vue'

const fastify = Fastify({ logger: true })

fastify.get('*', async (request, reply) => {
  const app = createSSRApp(App)

  // Server-side data fetching
  const initialState = await fetchInitialData(request.url)

  const html = await renderToString(app)

  reply.type('text/html').send(`
    <!DOCTYPE html>
    <html>
      <head>
        <title>Vue SSR</title>
        <script>window.__INITIAL_STATE__ = ${JSON.stringify(initialState).replace(/</g, '\\u003c')}</script>
      </head>
      <body>
        <div id="app">${html}</div>
        <script type="module" src="/src/entry-client.ts"></script>
      </body>
    </html>
  `)
})

fastify.listen({ port: 3000 })
```

```typescript
// entry-client.ts
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

// Hydrate with server state
if (window.__INITIAL_STATE__) {
  app.provide('initialState', window.__INITIAL_STATE__)
}

app.mount('#app')
```

```typescript
// vite.config.ts for SSR
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  build: {
    ssr: true,
    rollupOptions: {
      input: {
        server: './server.ts',
        client: './src/entry-client.ts'
      }
    }
  }
})
```


Escape `<` in serialized state (or use `devalue`) so a `</script>` inside data cannot break out of the tag.

## Hydration Patterns

### Hydration Mismatch Prevention

```vue
<script setup lang="ts">
import { onMounted, ref, useId } from 'vue'

// Values that differ between server and client render only after mount
const currentTime = ref<string | null>(null)
const windowWidth = ref<number | null>(null)
const inputId = useId() // stable across server and client (Vue 3.5+)

onMounted(() => {
  currentTime.value = new Date().toLocaleTimeString()
  windowWidth.value = window.innerWidth
})
</script>

<template>
  <div>
    <span v-if="currentTime">{{ currentTime }}</span>
    <span v-else>--:--:--</span>
    <span v-if="windowWidth !== null">Width: {{ windowWidth }}px</span>
    <label :for="inputId">Search</label>
    <input :id="inputId" type="search">
  </div>
</template>
```

Common causes: `Date.now()` or `Math.random()` in templates, locale or time zone formatting, `window` checks during setup, and invalid HTML nesting that the browser rewrites before hydration.

### Lazy Hydration (Vue 3.5+)

```ts
import { defineAsyncComponent, hydrateOnIdle, hydrateOnVisible } from 'vue'

// Server-renders normally; hydrates only when scrolled into view
const ReviewsList = defineAsyncComponent({
  loader: () => import('./components/ReviewsList.vue'),
  hydrate: hydrateOnVisible(),
})

// Hydrates when the browser is idle
const Newsletter = defineAsyncComponent({
  loader: () => import('./components/Newsletter.vue'),
  hydrate: hydrateOnIdle(),
})
```

Vue also provides `hydrateOnInteraction` and `hydrateOnMediaQuery`. Keep above-the-fold content on normal hydration. In Nuxt the same strategies are template props (`<LazyReviewsList hydrate-on-visible />`); see `nuxt-expert`.

## Quick Reference

| Pattern | Use Case |
|---------|----------|
| `createSSRApp()` | App instance for SSR and hydration |
| `renderToString()` | Render the app to HTML on the server |
| `useId()` | IDs that match on server and client |
| `onMounted()` | Client-only values without mismatches |
| `defineAsyncComponent({ hydrate })` | Lazy hydration strategies |
| Nuxt projects | Use the `nuxt-expert` skill |
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 323kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall