svelte-core-bestpractices
Svelte best practices for writing, editing, or reviewing Svelte/SvelteKit components and modules
Install / Use
npx skills add erayack/svelte-building-blocksInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Content & MediaSupported Platforms
Our assessment of svelte-core-bestpractices
svelte-core-bestpractices scores 76/100 on our quality scale, 567th of 736 Content & Media skills we index.
Its SKILL.md is 9.3 KB long, well organised into 19 sections with 14 code examples: a thorough specification that gives an agent plenty to work with.
It has no GitHub stars yet, so there is no community track record; judge it on its content.
Maintenance, license and trust
- The repository was last updated about 2 months ago, so svelte-core-bestpractices is actively maintained.
- Our last check on 2026-09-27 found the source still online.
- No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
- Its trust signals score 80/100, with 2 cautions from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.
AI review by kimi-k2.7-code on 2026-09-24. Automated pattern scan on 2026-09-24. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
svelte-core-bestpractices compared with similar skills
All 4 of these similar skills score higher than svelte-core-bestpractices; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| svelte-core-bestpractices (this skill)by erayack | 76 | 0 | 2mo ago | SKILL.md |
| siyuanby siyuan-note | 100 | 46.5k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 6d ago | SKILL.md |
| pptxby anthropics | 100 | 177.9k | 6d ago | SKILL.md |
| designby nextlevelbuilder | 100 | 130.2k | 7d ago | SKILL.md |
Frequently asked questions
- How do I install svelte-core-bestpractices?
- Run
npx skills add erayack/svelte-building-blocks. The install tabs above show the steps for each supported agent. - Which AI agents does svelte-core-bestpractices work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is svelte-core-bestpractices safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It declares no license and scores 80/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is svelte-core-bestpractices still maintained?
- The repository was last updated about 2 months ago, so svelte-core-bestpractices is actively maintained.
Skill content
View source on GitHubtitle: Best practices skill: true name: svelte-core-bestpractices description: Svelte best practices for writing, editing, or reviewing Svelte/SvelteKit components and modules. Use when touching Svelte reactivity, props, events, snippets, each blocks, styling, context, actions/attachments, stores, or Svelte 5 runes.
Process
-
Identify the Svelte mode before changing code.
- Check
package.jsonand existing components. - If the project already uses Svelte 5 runes, write new code in runes mode.
- If the touched area is legacy Svelte and a runes migration is not requested, keep the local style consistent.
- Done when the edit has one clear syntax mode for the touched files.
- Check
-
Put reactivity in the narrowest primitive that fits.
- Local reactive state:
$state. - Computed value:
$derivedor$derived.by. - Side effect or external subscription:
$effect,{@attach ...},createSubscriber, or an event handler, depending on the trigger. - Done when no
$effectis being used just to compute state.
- Local reactive state:
-
Keep state scoped.
- Component-only values stay local.
- Shared state that must be scoped to a subtree uses context.
- Shared module state is acceptable only when cross-user leakage is impossible or irrelevant.
- Done when SSR state cannot leak between users.
-
Review DOM boundaries.
- Lists use keyed each blocks with stable object identity.
- Global listeners use
<svelte:window>or<svelte:document>when possible. - Parent-to-child styling uses CSS custom properties before
:global. - Done when the DOM update and cleanup paths are explicit.
$state
Use $state only for values that should update a template expression, $derived, or $effect. Normal variables are fine for everything else.
Objects and arrays created with $state({ ... }) or $state([ ... ]) are deeply reactive. Mutation triggers updates, but proxying has overhead. For large values that are only reassigned, such as API responses, use $state.raw. Use $state.snapshot before passing proxy state to an external API or storing a moment-in-time copy.
Rune-enabled .svelte.js/.svelte.ts modules should export factories or objects with getters and named mutation methods. Do not export a rune variable that is reassigned internally, and avoid module-global mutable state when instances or SSR requests need isolation.
$derived
Use $derived for computed values.
let square = $derived(num * num);
Use $derived.by when the computation needs a function body.
let total = $derived.by(() => {
return items.reduce((sum, item) => sum + item.price, 0);
});
Do not use $effect to assign ordinary computed state.
// avoid
let square;
$effect(() => {
square = num * num;
});
Derived values are writable, but they re-evaluate when their dependencies change. If a derived expression returns an object or array, Svelte returns it as-is; it is not made deeply reactive.
$effect
Use $effect as an escape hatch for real side effects. Avoid writing Svelte state inside effects.
Choose the tighter tool when one exists:
- External library sync, such as D3:
{@attach ...}. - User-triggered work: the event handler or a function binding.
- Debug logging:
$inspect. - External reactive source:
createSubscriberfromsvelte/reactivity.
Effects do not run on the server, so if (browser) { ... } inside an effect is unnecessary.
$props
Treat props as changing values. Values that depend on props should usually be derived.
let { type } = $props();
let color = $derived(type === 'danger' ? 'red' : 'green');
This stale version should be avoided:
let { type } = $props();
let color = type === 'danger' ? 'red' : 'green';
$bindable
Use $bindable only when a child is intentionally an input-like controller for a parent-owned value. Keep domain operations such as add, save, or delete as callback props so mutation ownership stays visible.
$inspect.trace
Use $inspect.trace(label) to debug reactivity. Put it as the first line of an $effect, $derived.by, or a function called by them. It shows which dependency triggered the update.
Events
In modern Svelte, event listeners are element attributes that start with on.
<button onclick={() => save()}>save</button>
<button {onclick}>save</button>
<button {...props}>save</button>
For global targets, prefer Svelte elements over manual lifecycle wiring.
<svelte:window onkeydown={handleKeydown} />
<svelte:document onvisibilitychange={handleVisibilityChange} />
Snippets
Use snippets for reusable markup that can be rendered with {@render ...} or passed as props.
{#snippet greeting(name)}
<p>hello {name}!</p>
{/snippet}
{@render greeting('world')}
Declare snippets in the template. Top-level snippets can be referenced from <script>. A snippet that does not read component state can also be exported from <script module>.
Each blocks
Use keyed each blocks for lists with stable item identity.
{#each todos as todo (todo.id)}
<TodoItem {todo} />
{/each}
The key must uniquely identify the object. Use IDs, not array indexes.
If an item will be mutated with a binding such as bind:value={item.count}, avoid destructuring the item in the each block.
CSS from JavaScript values
Use CSS custom properties through the style: directive.
<div style:--columns={columns}>...</div>
.grid {
grid-template-columns: repeat(var(--columns), 1fr);
}
Styling child components
Use CSS custom properties as the parent-to-child styling hook.
<!-- Parent.svelte -->
<Child --color="red" />
<!-- Child.svelte -->
<h1>Hello</h1>
<style>
h1 {
color: var(--color);
}
</style>
Use :global only when the child cannot expose a styling hook, such as with some library components.
<div>
<Child />
</div>
<style>
div :global {
h1 {
color: red;
}
}
</style>
Attachments
Prefer {@attach ...} for new reusable DOM behavior. Return cleanup for every global listener or external resource. Existing use: actions remain valid for interoperability, but do not omit their destroy() path.
Error boundaries
Use <svelte:boundary> for local descendant rendering/effect failures and clear the failure condition before calling its reset function. Do not expect it to catch errors thrown directly by event handlers. In SvelteKit, keep route failures distinct: error(...) from load is handled by the nearest +error.svelte.
Context
Use context instead of shared-module state when state should be scoped to a component subtree. This is especially important during server-side rendering, where module state can leak between users.
Prefer createContext over setContext and getContext when possible because it provides type safety.
TypeScript and tests
Type component props, callbacks, snippets, and state collections when a project uses TypeScript, but continue runtime validation at server/API boundaries. Keep verification layers distinct: pure tests for logic, component-browser tests for isolated component contracts, end-to-end tests for complete running-app flows, and builds for bundling evidence.
Async Svelte
Svelte 5.36 and higher can use await expressions and hydratable promises directly inside components. These require experimental.async in svelte.config.js and are not fully stable.
Use async Svelte only when the project has already opted into that experimental mode.
Modern replacements
For new runes-mode code, prefer these replacements:
$statefor reactive state instead of implicitletreactivity.$derivedfor computed values instead of$:assignments.$effectfor side effects instead of$:statements.$propsinstead ofexport let,$$props, and$$restProps.onclick={...}instead ofon:click={...}.{#snippet ...}and{@render ...}instead of<slot>,$$slots, and<svelte:fragment>.<DynamicComponent>instead of<svelte:component this={DynamicComponent}>.import Self from './ThisComponent.svelte'and<Self>instead of<svelte:self>.- Classes with
$statefields for shared reactivity instead of stores when that state is part of a domain object. {@attach ...}for new DOM behavior; retainuse:actionwhere interoperability requires it.- Arrays and objects in
classattributes instead ofclass:directives.
Completion check
Before finishing a Svelte edit or review, verify every touched component/module against this list:
- State uses the narrowest reactive primitive.
- Computed values are derived, not effect-assigned.
- Effects are limited to real side effects or external subscriptions.
- Prop-dependent values update when props change.
- Lists with identity are keyed by stable IDs.
- Global listeners have a clear cleanup path or use Svelte global elements.
- Parent-to-child styling has an explicit CSS custom property hook when needed.
- Context is used where SSR-scoped shared state matters.
- Rune modules do not export reassigned state or leak accidental globals.
- Bindings are limited to deliberate input-like shared values.
- Route errors and component error boundaries are not conflated.
- TypeScript checks are paired with runtime validation at untrusted boundaries.
- Tests target the narrowest appropriate layer.
- New code follows the project's Svelte mode.
Related Skills
siyuan
46.5kAn open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
pptx
177.9kUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an em…
design
130.2kComprehensive design skill: brand identity, design tokens, UI styling, logo generation (55 styles, Gemini, Atlas Cloud, or MuAPI AI), corporate identity program (50 deliverables, CIP mockups), HTML presentations (Chart.js), banner design (22 styles, social/ads/web/print), icon design (15 styles, SVG…
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
