askill
svelte5

svelte5Safety 90Repository

Svelte 5 guidance — runes ($state, $derived, $effect, $props, $bindable), class-based state management, reactive patterns, context API, snippets vs slots, and Svelte 4→5 migration. Use for any Svelte 5 reactivity question, component props, sharing state across components, or migrating from writable/readable stores. Triggers on: $state, $derived, $effect, $props, $bindable, runes, Svelte 5, .svelte.ts, writable, readable, stores migration.

2 stars
1.2k downloads
Updated 2/19/2026

Package Files

Loading files...
SKILL.md

Svelte 5

Svelte 5 replaces stores with runes (reactive primitives) and class-based state (the idiomatic replacement for writable/readable). Don't mix Svelte 4 and 5 syntax — pick one.

Topics

TopicFile
Rune patterns, Svelte 4→5 migration, component APIrunes.md
Class patterns, context API, SSR safetyclass-state.md

Runes Quick Reference

Which rune? State: $state() | Computed: $derived() | Side effect: $effect() | Props: $props() | Bindable: $bindable()

Runes are top-level only — you can't call them inside functions or blocks.

<script>
  let count = $state(0);
  const doubled = $derived(count * 2);

  $effect(() => {
    console.log(`Count is ${count}`);
  });
</script>

<button onclick={() => count++}>
  {count} (doubled: {doubled})
</button>

Key behaviors:

  • Objects and arrays are deeply reactive by default
  • $derived can be reassigned (Svelte 5.25+) — use const for read-only derived values
  • Event handlers: onclick not on:click
  • Children: {@render children()} not <slot />

→ Deep dives: runes.md for full rune patterns, migration guide, and component API.

Class-Based State

Classes with $state fields are the idiomatic way to manage client-side state. More performant than stores, better TypeScript support, cleaner encapsulation.

File extension: .svelte.ts required for $state outside components.

// CounterState.svelte.ts
interface CounterState {
  count: number;
  increment: () => void;
}

class CounterStateClass implements CounterState {
  count = $state(0);
  increment = () => { this.count++; };  // Arrow methods avoid `this` binding issues
}

export const createCounterState = () => new CounterStateClass();
<script>
  import { createCounterState } from './CounterState.svelte';
  const state = createCounterState();
</script>
<button onclick={state.increment}>{state.count}</button>

Sharing State (Context API)

Local only → instantiate directly. Shared across components → use context:

// CounterState.svelte.ts
import { getContext, setContext, hasContext } from 'svelte';

const KEY = Symbol('counter');  // Symbol keys avoid collisions
export const setCounterState = () => setContext(KEY, new CounterStateClass());
export const getCounterState = () => {
  if (!hasContext(KEY)) throw new Error('Counter context not set');
  return getContext<CounterState>(KEY);
};
<!-- Parent: set context -->
<script>
  import { setCounterState } from './CounterState.svelte';
  setCounterState();
</script>

<!-- Any descendant: consume -->
<script>
  import { getCounterState } from './CounterState.svelte';
  const state = getCounterState();
</script>

⚠️ SvelteKit users: Never export module-level state instances — causes SSR leaks where state bleeds between requests.

→ Deep dives: class-state.md for arrays, timers, async patterns, and context vs scoped decisions.

Common Mistakes

MistakeFix
on:click={handler}onclick={handler} (Svelte 5 syntax)
<slot />{@render children()}
$state inside a functionMove to top level of <script> or class field
Exporting module-level $state instanceUse factory function or context API
let x = $derived(...) then reassigningUse const if you want read-only
.ts extension for reactive filesMust be .svelte.ts for $state outside components
Mixing writable()/readable() with runesPick one — don't mix Svelte 4/5 patterns

Reference Index

Runes: Reactivity Patterns · Migration Gotchas · Component API · Snippets vs Slots · Common Mistakes

Class State: Class Patterns · Context vs Scoped · Common Mistakes · SSR Safety

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

82/100Analyzed 2/24/2026

High-quality Svelte 5 reference skill with excellent clarity and structure. Provides comprehensive coverage of runes, class-based state, and migration patterns with actionable code examples. The skill includes a clear trigger section, useful tags, and well-organized reference tables. Minor gaps: relies on external referenced files for deep dives, no explicit icon in metadata, and path doesn't follow dedicated skills folder convention. Content is well-suited for general use rather than internal-only.

90
92
90
75
72

Metadata

Licenseunknown
Version-
Updated2/19/2026
Publisherjoshuadavidthomas

Tags

api