.cursorrunes for Svelte 5
Add this skill
npx mdskills install PatrickJS/cursor-svelte-5-vs-svelte-4Provides clear Svelte 4 to 5 migration rules but lacks agent instructions or trigger conditions
1I'm using svelte 5 instead of svelte 4 here is an overview of the changes.2# .cursorrunes for Svelte 534## Overview of Changes56Svelte 5 introduces runes, a set of advanced primitives for controlling reactivity. The runes replace certain non-runes features and provide more explicit control over state and effects.78Snippets, along with render tags, help create reusable chunks of markup inside your components, reducing duplication and enhancing maintainability.910## Event Handlers in Svelte 51112In Svelte 5, event handlers are treated as standard HTML properties rather than Svelte-specific directives, simplifying their use and integrating them more closely with the rest of the properties in the component.1314### Svelte 4 vs. Svelte 5:1516**Before (Svelte 4):**17```html18<script>19 let count = 0;20 $: double = count * 2;21 $: {22 if (count > 10) alert('Too high!');23 }24</script>25<button on:click={() => count++}> {count} / {double}</button>26```2728**After (Svelte 5):**29```html30<script>31 import { $state, $effect, $derived } from 'svelte';3233 // Define state with runes34 let count = $state(0);3536 // Option 1: Using $derived for computed values37 let double = $derived(count * 2);3839 // Reactive effects using runes40 $effect(() => {41 if (count > 10) alert('Too high!');42 });43</script>4445<!-- Standard HTML event attributes instead of Svelte directives -->46<button onclick={() => count++}>47 {count} / {double}48</button>4950<!-- Alternatively, you can compute values inline -->51<!-- <button onclick={() => count++}>52 {count} / {count * 2}53</button> -->54```5556## Key Differences:57581. **Reactivity is Explicit**:59 - Svelte 5 uses `$state()` to explicitly mark reactive variables60 - `$derived()` replaces `$:` for computed values61 - `$effect()` replaces `$: {}` blocks for side effects62632. **Event Handling is Standardized**:64 - Svelte 4: `on:click={handler}`65 - Svelte 5: `onclick={handler}`66673. **Import Runes**:68 - All runes must be imported from 'svelte': `import { $state, $effect, $derived, $props, $slots } from 'svelte';`69704. **No More Event Modifiers**:71 - Svelte 4: `on:click|preventDefault={handler}`72 - Svelte 5: `onclick={e => { e.preventDefault(); handler(e); }}`7374This creates clearer, more maintainable components compared to Svelte 4's previous syntax by making reactivity explicit and using standardized web platform features.75
Full transparency — inspect the skill content before installing.