Svelte Runes

spences10/svelte-skills-kit/plugins/svelte-skills/skills/svelte-runes

作者 spences102a9d88379bf62cee464a16db852edda7790a58f5無授權條款收錄於 2026年10月9日更新於 2026年10月9日

Svelte runes guidance. Use for reactive state, props, effects, or migration. Covers $state, $derived, $effect, $props, $bindable. Prevents reactivity mistakes.

AI 產生的概覽

指導 Svelte 5 runes 的用法,涵蓋響應式狀態、props、effect 以及從 Svelte 4 遷移。

功能
提供關於 Svelte 5 runes 的簡明指引,涵蓋 $state、$derived、$effect、$props 與 $bindable,並附有快速規則清單和一段簡短程式碼範例。同時指向隨附的參考檔案,內容涉及響應式模式、遷移注意事項、元件 API、snippets 與 slots 的比較以及常見錯誤。此技能僅包含說明,不會產生檔案或指令碼。
適用情境
適用於撰寫或審查依賴 runes 實現響應式狀態、計算值、副作用或 props 的 Svelte 5 元件。也適合將 Svelte 4 程式庫遷移到 Svelte 5 語法,或排查響應式問題時使用。
執行需求
不需要任何工具、套件或憑證;此技能僅包含說明與參考文件,不附帶指令碼。

Svelte Runes

Quick Start

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

Key rules: Runes are top-level only. $derived can be overridden (use const for read-only). Don't mix Svelte 4/5 syntax. Objects/arrays are deeply reactive by default.

Example

svelte
<script>	let count = $state(0); // Mutable state	const doubled = $derived(count * 2); // Computed (const = read-only)
	$effect(() => {		console.log(`Count is ${count}`); // Side effect	});</script>
<button onclick={() => count++}>	{count} (doubled: {doubled})</button>

Reference Files

  • reactivity-patterns.md [blocked] - When to use each rune
  • migration-gotchas.md [blocked] - Svelte 4→5 translation
  • component-api.md [blocked] - $props, $bindable patterns
  • snippets-vs-slots.md [blocked] - New snippet syntax
  • common-mistakes.md [blocked] - Anti-patterns with fixes

For @attach and other template directives, see the svelte-template-directives skill.

Notes

  • Use onclick not on:click, {@render children()} in layouts
  • $derived can be reassigned (5.25+) - use const for read-only
  • Use createContext over setContext/getContext for type safety
  • Use $inspect.trace to debug reactivity issues
  • Last verified: 2026-03-12
<!-- PROGRESSIVE DISCLOSURE GUIDELINES: - Keep this file ~50 lines total (max ~150 lines) - Use 1-2 code blocks only (recommend 1) - Keep description <200 chars for Level 1 efficiency - Move detailed docs to references/ for Level 3 loading - This is Level 2 - quick reference ONLY, not a manual LLM WORKFLOW (when editing this file): 1. Write/edit SKILL.md 2. Format (if formatter available) 3. Run: npx skills add . --list 4. If the skill is not discovered, check SKILL.md frontmatter formatting 5. Validate again to confirm -->

來源與署名

來源:spences10/svelte-skills-kit位於plugins/svelte-skills/skills/svelte-runes提交2a9d883

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架