svelte-core-bestpractices

Guide Svelte 5 component reactivity using runes and recommended patterns.

6|Updated Mar 26, 2026
One-click install
npx skills add https://github.com/memoirlabs/mog --skill svelte-core-bestpractices-memoirlabs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: svelte-core-bestpractices
Source: https://github.com/memoirlabs/mog/tree/main/.agents/skills/svelte-core-bestpractices
Command: npx skills add https://github.com/memoirlabs/mog --skill svelte-core-bestpractices-memoirlabs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you avoid common Svelte 5 performance and correctness pitfalls by guiding you to use the recommended runes and patterns for reactivity, events, context, styling, and async rendering.

Core Features & Use Cases

  • Correct reactivity with runes: Prefer $state for reactive state, $derived for derived values, and reserve $effect for true side effects to prevent update bugs and unnecessary reruns.
  • Event and lifecycle best practices: Attach event listeners with on* attributes and use svelte:window / svelte:document instead of onMount for external events.
  • Maintainable UI composition: Use keyed {#each} blocks, snippets ({#snippet ...} / {@render ...}), and CSS scoping patterns to keep components predictable and performant.
  • Async and SSR guidance: Apply await in supported Svelte 5.36+ contexts, understand boundaries/pending, and use hydratable when needed to keep SSR and hydration consistent.

Quick Start

Load this skill and ask for guidance to rewrite a Svelte component so it uses runes correctly (for example, replacing incorrect $effect/$: usage with $derived and $state), while improving performance and update behavior.

Frequently Asked Questions about svelte-core-bestpractices

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

FAQPage Schema
How do I use Svelte 5 runes correctly for component reactivity?

Replace $effect with $derived for computed values in Svelte 5 because $effect triggers unnecessary reruns and update bugs, whereas $derived computes efficiently without side effects.

What's the best way to handle event listeners in Svelte components?

Handle event listeners in Svelte by attaching them with on* attributes and using svelte:window or svelte:document instead of onMount for external events to ensure proper lifecycle management.

How do I write keyed each blocks and snippets for UI composition in Svelte?

Write keyed each blocks and snippets in Svelte by using {#each ...} with keys and {#snippet ...} / {@render ...} syntax to keep UI components predictable and performant during updates.

Does Svelte 5 support await in SSR and how do I manage hydration?

Svelte 5.36+ supports await in specific SSR contexts with proper boundaries and pending states, using hydratable when needed to keep SSR and hydration consistent.

When should I not use $effect in Svelte 5?

Do not use $effect in Svelte 5 for derivations or computations; reserve it strictly for true side effects like manual DOM manipulations or external subscriptions to avoid update bugs and infinite reruns.