All skills
sveltejs avatar

/svelte-core-bestpractices

@1eb06fd official
by Sveltesveltejs/mcp331 stars
40

Guidance on writing fast, robust, modern Svelte code. Load this skill whenever in a Svelte project and asked to write/edit or analyze a Svelte component or module. Covers reactivity, event handling, styling, integration with libraries and more.

Use this Skill: https://skilld.dev/gh/sveltejs/mcp/svelte-core-bestpractices

This session only. Nothing lands on disk.

referenceseach.md

≈300 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Keyed each blocks

<!--- copy: false  --->
{#each expression as name (key)}...{/each}
<!--- copy: false  --->
{#each expression as name, index (key)}...{/each}

If a key expression is provided — which must uniquely identify each list item — Svelte will use it to intelligently update the list when data changes by inserting, moving and deleting items, rather than adding or removing items at the end and updating the state in the middle.

The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change.

{#each items as item (item.id)}
	<li>{item.name} x {item.qty}</li>
{/each}

<!-- or with additional index value -->
{#each items as item, i (item.id)}
	<li>{i + 1}: {item.name} x {item.qty}</li>
{/each}

You can freely use destructuring and rest patterns in each blocks.

{#each items as { id, name, qty }, i (id)}
	<li>{i + 1}: {name} x {qty}</li>
{/each}

{#each objects as { id, ...rest }}
	<li><span>{id}</span><MyComponent {...rest} /></li>
{/each}

{#each items as [id, ...rest]}
	<li><span>{id}</span><MyComponent values={rest} /></li>
{/each}

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides legitimate guidance and best practices for Svelte 5 development. It contains only documentation and code examples with no identified security risks.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    10 files scanned · No issues

  • ZeroLeaks5mo

    1 finding · Score: 86/100

Signed by skilld at 1eb06fd. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 2 months ago
  • svelte
  • reactivity
  • runes
  • components
  • styling
  • state-management
  • event-handling
  • best-practices
  • svelte5

README badge

README badge for sveltejs/mcp/svelte-core-bestpractices

Provides best practices for writing Svelte 5 components using runes (`$state`, `$derived`, `$effect`, `$props`), event handling, snippets, styling, and context. Load this skill in Svelte projects when writing or reviewing components to ensure idiomatic reactivity patterns and avoid legacy features.

Generated from the current SKILL.md.

Should I use $state for all variables?
No. Only use $state for variables that should be reactive and trigger updates in effects, derived values, or templates. Regular variables can stay as normal JavaScript. For large objects that are only reassigned (not mutated), use $state.raw instead to avoid proxy overhead.
When should I use $derived instead of $effect?
$derived should be your first choice for computing values from state. Use $effect only as an escape hatch for side effects like syncing to external libraries. Never use $effect just to update a variable based on state changes.
Can I use $effect to listen to window or document events?
No. Use <svelte:window> and <svelte:document> instead. Avoid $effect or onMount for attaching global event listeners.
What should I use instead of on:click and other legacy event directives?
Use the onclick attribute directly (e.g. <button onclick={() => {...}}>), which works with attribute shorthand and spread props.
Should I destructure items in each blocks if I need to bind to them?
No. Avoid destructuring if you need to mutate the item with something like bind:value={item.count}, as it can break reactivity.

Generated from the current SKILL.md. These answers refresh after source changes.