ams-svelte-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Svelte Pro
Overview
Svelte's bet — a compiler instead of a runtime — means idiomatic Svelte looks deceptively
simple: $state, $derived, $effect (runes) declare reactivity, and the compiler generates the
surgical DOM updates. Professional Svelte means thinking in runes correctly (universal reactivity),
structuring SvelteKit apps around its data-loading model, and keeping components small and honest.
The through-line: write straightforward code; let the compiler do the clever work.
When to use
- Writing or reviewing Svelte 5 (runes mode) code.
- Structuring SvelteKit applications (routing, load functions, forms).
- Designing component APIs (props, snippets, events).
- Debugging reactivity issues in runes mode.
- Optimizing Svelte rendering or bundle size.
Core concepts
- Runes: universal reactivity.
$statefor reactive values (deeply reactive proxies — mutate freely),$derivedfor computed values,$effectfor side effects. Runes work in.svelte.jsmodules too — shared reactive state without component boilerplate. - Props as runes.
$props()destructures component inputs;$bindable()marks two-way-bound props explicitly. No moreexport let— and prop mutation rules are now explicit instead of accidental. - Effects are for side effects.
$effectsyncs with the outside world (DOM measurements, subscriptions, persistence) — with cleanup returned. Deriving values in effects instead of$derivedis the classic runes mistake. - Snippets over slots.
{@render children()}and named snippets replace slots with a more composable, typed API. Snippets are just functions returning markup — pass them as props for powerful composition patterns. - SvelteKit's data model.
loadfunctions (server-first, progressively enhanced), form actions (no-JS-baseline forms that enhance), and thedataprop flow. Design around server load + actions before reaching for client-side fetching. - Stores, evolved. The classic store contract (
subscribe) still works and interoperates; runes in modules cover most new shared-state needs. Don't mix paradigms confusingly — pick per boundary.
Practical workflow
- Scaffold with SvelteKit.
npm create svelte@latest; TypeScript; ESLint + Prettier; routes mirror the URL structure (src/routes/...). - Design data flow per route.
+page.server.tsloadfor data (validated, typed);+page.svelterenders fromdata; formactionsfor mutations withuse:enhancefor progressive enhancement. Client fetches only for truly client-side concerns. - Write components small. Props in via
$props(), events via callbacks (props), content via snippets. Keep components focused; extract runes-based logic into.svelte.jsmodules when shared. - Handle async states. Await blocks (
{#await}) or runes-based loading state in load functions; error boundaries via+error.svelte; loading UI via+page.svelteskeletons. - Test behavior. Vitest for logic and runes modules;
@testing-library/sveltefor component behavior; Playwright for critical journeys (SvelteKit's first-class testing story). - Keep bundles lean. The compiler already minimizes runtime — your job is route-level code splitting (automatic), avoiding heavy deps in shared chunks, and measuring with the bundle analyzer before optimizing.
Idiomatic snippets:
<script>
let { userId } = $props();
let filter = $state('');
// $derived, not $effect, for computed values
let visible = $derived(orders.filter(o => o.id.includes(filter)));
let total = $derived(visible.reduce((s, o) => s + o.total, 0));
// $effect only for side effects, with cleanup
$effect(() => {
document.title = `Orders (${visible.length})`;
const t = setInterval(refresh, 30_000);
return () => clearInterval(t);
});
</script>
Common pitfalls
$effectfor derived state. Computing values inside effects instead of$derived— causes unnecessary runs, ordering bugs, and confusion. Derived =$derived, always.- Deep mutation surprises.
$stateproxies are deeply reactive — convenient, but mutating nested objects triggers fine-grained updates you might not expect. For large replace-whole objects, that's fine; for huge collections with frequent tiny updates, consider structure. - Forgetting runes mode boundaries. Legacy-mode (
export let) and runes-mode idioms mixed in one codebase. Migrate deliberately; don't straddle. - Client-fetching what load() should do.
onMount(fetch(...))for initial page data — loses SSR, SEO, and SvelteKit's loading/error semantics. Serverloadfirst. - Props drilling through 5 layers. Either the state belongs in a shared runes module, or the component tree needs restructuring (composition with snippets).
- No cleanup in effects. Subscriptions, intervals, and observers without returned cleanup —
leaks that accumulate in SPAs. Every
$effectwith setup returns teardown. - Over-fetching in load. Returning the whole database from
load"for flexibility." Load what the page needs; use streaming promises for deferred secondary data.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).