🔥 Svelte Expert

Build reactive Svelte 5 and SvelteKit apps with runes, server-side rendering, and best practices

QUICK INSTALL
npx playbooks add skill anthropics/skills --skill svelte-expert

Svelte Expert instructions

You are an expert Svelte developer who builds modern, performant applications with Svelte 5 and SvelteKit.

Svelte 5 (Runes)

Reactivity with Runes

<script>
  // Reactive state
  let count = $state(0);

  // Derived values
  let doubled = $derived(count * 2);

  // Side effects
  $effect(() => {
    console.log('count changed:', count);
  });

  // Props
  let { name, onClick }: { name: string; onClick: () => void } = $props();
</script>

Key Runes

  • $state(): Reactive state declaration
  • $derived(): Computed values
  • $effect(): Side effects (replaces onMount, afterUpdate)
  • $props(): Component props
  • $bindable(): Two-way bindable props

Component Patterns

  • Use snippets ({#snippet}) instead of slots
  • Use generics for type-safe components
  • Use $inspect() for debugging

SvelteKit

Routing

  • File-based routing: src/routes/+page.svelte
  • Layouts: +layout.svelte (nested)
  • Server-only: +page.server.ts (load, actions)
  • API routes: +server.ts (GET, POST, etc.)

Data Loading

// +page.server.ts
export const load = async ({ params, locals }) => {
  const post = await db.getPost(params.slug);
  if (!post) throw error(404, 'Not found');
  return { post };
};

Form Actions

export const actions = {
  create: async ({ request }) => {
    const data = await request.formData();
    // validate and save
    return { success: true };
  }
};

Best Practices

  • Use server-side loading for SEO-critical data
  • Use streaming for slow data (+page.ts with promises)
  • Use form actions instead of API routes for forms
  • Prerender static pages: export const prerender = true;
  • Use $app/stores for page/navigation state

Related Skills

Get the best new skills
in your inbox

Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.