mcpField
S
svelte-template-directives

svelte-template-directives

github.com/spences10Development94491 installsUpdated 2w ago
Repository

About svelte-template-directives

A Svelte reference skill for template directives, with emphasis on Svelte 5 attachments and their differences from legacy actions. It is intended for developers implementing reactive DOM behavior and consulting concise directive guidance.

Key features

  1. 01Svelte directive quick reference
  2. 02Reactive @attach usage patterns
  3. 03Comparison with use: actions
  4. 04Legacy action conversion guidance
  5. 05Keyed each-block reminders

Use cases

  1. 01Adding reactive DOM behavior
  2. 02Integrating third-party DOM libraries
  3. 03Converting legacy actions to attachments
  4. 04Checking Svelte template directive usage

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/spences10/svelte-skills-kit --skill svelte-template-directives

After installing, type/svelte-template-directivesin Claude Code to confirm it loaded.

Bundled filesreferences/attach-patterns.mdreferences/other-directives.md

Details

From the project README

Svelte Template Directives

@attach (Svelte 5.29+)

The reactive alternative to use: actions. Re-runs when dependencies change, passes through components via spread, supports cleanup functions.

<script>
	import ImageZoom from 'js-image-zoom';

	function useZoom(options) {
		return (element) => {
			new ImageZoom(element, options);
			return () => console.log('cleanup');
		};
	}
</script>

<!-- Re-runs if options changes (use: wouldn't!) -->
<figure {@attach useZoom({ width: 400 })}>
	<img src="photo.jpg" alt="zoomable" />
</figure>

Quick Reference

DirectivePurposeReactive?
{@attach}DOM manipulation, 3rd-partyYes
{@html}Render raw HTML stringsYes
{@render}Render snippetsYes
{@const}Local constants in blocksN/A
{@debug}Pause debugger on value changeN/A
{#each (key)}Keyed iteration (always key!)Yes
<svelte:window>Window event listenersN/A

@attach vs use: Actions

Featureuse:@attach
Re-runs on arg changeNoYes
ComposableLimitedFully
Pass through propsManualAuto via spread
Convert legacyN/AfromAction()

Reference Files

Notes

  • @attach requires Svelte 5.29+
  • Use fromAction from svelte/attachments to convert legacy actions
  • Attachments pass through wrapper components when you spread props
  • Always use keyed each blocks — never use index as key
  • Use <svelte:window>/<svelte:document> for global events, not $effect
  • Last verified: 2026-03-12

Comments

Markdown supported