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 从公开仓库中收录这些内容。

举报或申请下架