vueuse-best-practices

Enforce SSR-safe VueUse composable patterns in Vue 3 projects.

1|Updated Apr 4, 2023
One-click install
npx skills add https://github.com/ElderEvil/falloutProject --skill vueuse-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vueuse-best-practices
Source: https://github.com/ElderEvil/falloutProject/tree/main/.agents/skills/vueuse-best-practices
Command: npx skills add https://github.com/ElderEvil/falloutProject --skill vueuse-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

VueUse is a powerful collection of composables, but developers often face SSR hydration issues, browser API dependencies, and inconsistent type inference. This skill provides best practices to write safe, SSR-friendly VueUse code and to resolve common pitfalls in Vue 3 projects.

Core Features & Use Cases

  • SSR-safe patterns: Prefer built-in SSR-safe VueUse utilities and guard browser APIs with onMounted or isClient.
  • Type-safe composition: Use MaybeElementRef and template refs to ensure predictable behavior across client/server.
  • Debug and integration: Apply strategies when debugging VueUse SSR issues or integrating VueUse with Nuxt/Vite.
  • Use Case: In a Vue 3 app with SSR, create a composable that safely reads window size on the client only.

Quick Start

  • Review the VueUse best practices guide and apply onMounted and isClient checks in your components.
  • Validate SSR safety by simulating server rendering and verifying hydration parity.
  • Ensure no browser-only APIs run during server rendering.

Frequently Asked Questions about vueuse-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix VueUse SSR hydration issues in Vue 3?

To fix VueUse SSR hydration issues, guard browser API access using onMounted and isClient checks to ensure server-side rendering executes no client-only logic. This prevents hydration mismatches by verifying hydration parity between server and client output.

What is the best way to access the window object safely with VueUse composables?

The best way to access the window object safely is wrapping browser API calls in onMounted or isClient conditionals to restrict execution to the client. This SSR-safe pattern prevents server rendering errors and DOM access pitfalls.

How do I ensure type-safe composition when using VueUse template refs?

To ensure type-safe composition with VueUse template refs, use MaybeElementRef to guarantee predictable behavior across client and server environments. This approach enforces type safety and prevents inconsistent type inference during SSR.

Does VueUse work with Nuxt and Vite for server-side rendered applications?

VueUse works with Nuxt and Vite by applying SSR-safe patterns and leveraging built-in SSR-safe utilities for server-side rendered applications. You must validate SSR safety by simulating server rendering and verifying hydration parity.

Why does my Vue 3 composable fail during server rendering?

Your Vue 3 composable fails during server rendering because browser-only APIs are executing outside the client environment. Apply isClient checks and client-only rendering patterns to ensure no browser APIs run during server rendering.