Svelte

From G1Joshi/Agent-Skills · View interactive version

Svelte is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Svelte assistance covering Svelte 5 Runes, reactive declarations, stores, animations, and transitions. Use when building fast, reactive web UIs with minimal boilerplate.

How to use this skill

Skill file

Svelte

Svelte compiles declarative components into minimal vanilla JavaScript, utilizing explicit Runes for fine-grained reactivity without Virtual DOM overhead.

When to Use

Quick Start

<script>
  let count = $state(0);
  let double = $derived(count * 2);

  function increment() {
    count += 1;
  }
</script>

<button onclick={increment}>
  Count: {count} / Double: {double}
</button>

Core Concepts

Runes

Svelte 5 reactivity markers.

Snippets

Reusable chunks of markup within a component.

{#snippet figure(src, caption)}
  <figure>
    <img {src} alt={caption} />
    <figcaption>{caption}</figcaption>
  </figure>
{/snippet}

{@render figure(imageSrc, "A nice image")}

Common Patterns

Svelte 5 Runes for Fine-Grained Reactive State

Problem: Legacy Svelte 3/4 let bindings and $: labels lack universal TypeScript ergonomics across .svelte.ts modules.

Solution:

Use modern Svelte 5 Runes ($state, $derived, $effect):

<script lang="ts">
  let count = $state(0);
  let double = $derived(count * 2);

  $effect(() => {
    console.log(`Count changed to: ${count}`);
  });
</script>

<button on:click={() => count++}>
  Count: {count} (Double: {double})
</button>

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :---------------------------------------------------------- | :---------------------------------------------------------------- | :--------------------------------------------------------------------------------------- |

| Array/Object mutation not triggering update in Svelte 3/4 | Mutating array in-place without reassignment (arr.push(x)). | Reassign array: arr = [...arr, x] or upgrade to Svelte 5 $state(). |

| Cannot bind to undefined property | Missing export let propName in child component definition. | Declare export let propName; (Svelte 3/4) or let { propName } = $props() (Svelte 5). |

| Component is not defined in script | Typo in import or relative path missing .svelte file extension. | Include explicit .svelte extension on component imports. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.