协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
svelte【开发与工程】Modern Svelte 5 and SvelteKit development covering runes-based reactivity, snippets, SSR/SSG, and state management, including migration notes from legacy Svelte 4 syntax. Use when writing or reviewing Svelte components, deciding between runes and legacy reactive statements, building SvelteKit routes and load functions, or migrating a Svelte 4 codebas…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
This skill covers Svelte and SvelteKit development with deep knowledge of SSR, SSG, and modern web patterns, including the Svelte 5 runes system and how it differs from legacy Svelte 4 reactivity.
Svelte 5 introduces runes — compiler-level primitives that make reactivity explicit, replacing Svelte 4's implicit let/$: reactivity.
$state for reactive state (replaces plain let bindings that needed reactivity)$derived for computed values (replaces $: computed = ...)$effect for side effects (replaces $: { ... } blocks)$props for component properties (replaces export let prop)$bindable for two-way bindable props (replaces implicit bind: support on exported props)$inspect during development to log reactive value changesimport { $state } from 'svelte'. Only import genuine utilities that still require it, such as tick, untrack, mount, or unmount.Svelte 4 (legacy reactivity):
<script>
let count = 0;
$: double = count * 2;
$: {
if (count > 10) alert('Too high!');
}
</script>
<button on:click={() => count++}>{count} / {double}</button>
Svelte 5 (runes):
<script>
let count = $state(0);
let double = $derived(count * 2);
$effect(() => {
if (count > 10) alert('Too high!');
});
</script>
<button onclick={() => count++}>{count} / {double}</button>
Key differences to apply when writing or reviewing components:
$state() marks reactive variables, $derived() replaces $: for computed values, $effect() replaces $: {} blocks for side effects.onclick={handler}) instead of Svelte-specific directives (on:click={handler}). There are no more event modifiers like |preventDefault; call e.preventDefault() inline instead: onclick={e => { e.preventDefault(); handler(e); }}.let { propName } = $props() instead of multiple export let propName declarations. Mark a prop bindable from the parent with $bindable().{#snippet name(params)}...{/snippet} and {@render name(args)} reduce duplication and are more composable than named slots. Existing <slot> usage still works but prefer snippets in new Svelte 5 code.When maintaining an existing Svelte 4 codebase, keep using export let, on:event, and $: reactive statements consistently within that codebase rather than mixing paradigms — full-file migrations to runes should be deliberate, not incidental.
<style> tags@apply directives$state in .svelte.js/.svelte.ts modules under Svelte 5) for shared state$state fields for reactive class properties