Windsurf rules for Svelte 5 and SvelteKit 2 with TypeScript: runes-based components, typed load functions and form actions without throw, and safe shared state.
.devin/rules/svelte-development-for-windsurf.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
Apply these rules to Svelte and SvelteKit code. They target Svelte 5 (runes) and SvelteKit 2; check package.json first.
## Component structure
```svelte
<script lang="ts">
import type { User } from '$lib/types';
let { user }: { user: User | null } = $props();
let showEmail = $state(false);
</script>
{#if user}
<h1>{user.name}</h1>
<button type="button" onclick={() => (showEmail = !showEmail)}>
{showEmail ? 'Hide' : 'Show'} email
</button>
{#if showEmail}<p>{user.email}</p>{/if}
{:else}
<p>User not found</p>
{/if}
```
- Load data in a SvelteKit `load` function and pass it in as props, instead of fetching in `onMount`; the page then renders on the server and has no loading flash.
- Use `$props`, `$state`, `$derived` and `onclick`; do not mix with `export let`, `$:` or `on:click` in the same component.
## SvelteKit load
```ts
// src/routes/posts/[id]/+page.server.ts
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { db } from '$lib/server/db';
export const load: PageServerLoad = async ({ params }) => {
const post = await db.post.findUnique({ where: { id: params.id } });
if (!post) error(404, 'Not found');
return { post };
};
```
## Form actions
```ts
// src/routes/posts/new/+page.server.ts
import { error, fail, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import { db } from '$lib/server/db';
export const actions = {
default: async ({ request, locals }) => {
if (!locals.user) error(401, 'Sign in first');
const data = await request.formData();
const title = data.get('title');
if (typeof title !== 'string' || !title.trim()) return fail(400, { missing: true });
await db.post.create({ data: { title: title.trim(), authorId: locals.user.id } });
redirect(303, '/posts');
},
} satisfies Actions;
```
- In SvelteKit 2, `error()` and `redirect()` throw for you; do not prefix them with `throw`. Import `error` from `@sveltejs/kit` wherever it is used.
## Shared state
```ts
// src/lib/state/session.svelte.ts — client-side UI state only
export const ui = $state({ sidebarOpen: false });
```
- Stores from `svelte/store` still work (`writable<User | null>(null)`), but never keep per-user data in module-level state or stores in SvelteKit: on the server those modules are shared between requests. Get the user from `locals` in `load`.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
CLAUDE.md rules for React 19 with TypeScript covering typed components, derived state, compiler-aware memoization, useId-based accessibility and review checks.
Windsurf
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Windsurf SvelteKit 2 + Svelte 5 project fetches the user in onMount, uses export let, writes throw error(404) without importing error, and keeps the logged-in user in a module-level writable.
Update src/routes/posts/[id] and src/lib/stores/user.ts following the Svelte development rule.
Data loaded in +page.server.ts with PageServerLoad and error(404) (imported, no throw), the component using $props/$state/onclick, the action checking locals.user and validating FormData, and the global user store replaced by locals + layout data.
Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/svelte-development-for-windsurf.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
Apply these rules to Svelte and SvelteKit code. They target Svelte 5 (runes) and SvelteKit 2; check package.json first.
## Component structure
```svelte
<script lang="ts">
import type { User } from '$lib/types';
let { user }: { user: User | null } = $props();
let showEmail = $state(false);
</script>
{#if user}
<h1>{user.name}</h1>
<button type="button" onclick={() => (showEmail = !showEmail)}>
{showEmail ? 'Hide' : 'Show'} email
</button>
{#if showEmail}<p>{user.email}</p>{/if}
{:else}
<p>User not found</p>
{/if}
```
- Load data in a SvelteKit `load` function and pass it in as props, instead of fetching in `onMount`; the page then renders on the server and has no loading flash.
- Use `$props`, `$state`, `$derived` and `onclick`; do not mix with `export let`, `$:` or `on:click` in the same component.
## SvelteKit load
```ts
// src/routes/posts/[id]/+page.server.ts
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { db } from '$lib/server/db';
export const load: PageServerLoad = async ({ params }) => {
const post = await db.post.findUnique({ where: { id: params.id } });
if (!post) error(404, 'Not found');
return { post };
};
```
## Form actions
```ts
// src/routes/posts/new/+page.server.ts
import { error, fail, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
import { db } from '$lib/server/db';
export const actions = {
default: async ({ request, locals }) => {
if (!locals.user) error(401, 'Sign in first');
const data = await request.formData();
const title = data.get('title');
if (typeof title !== 'string' || !title.trim()) return fail(400, { missing: true });
await db.post.create({ data: { title: title.trim(), authorId: locals.user.id } });
redirect(303, '/posts');
},
} satisfies Actions;
```
- In SvelteKit 2, `error()` and `redirect()` throw for you; do not prefix them with `throw`. Import `error` from `@sveltejs/kit` wherever it is used.
## Shared state
```ts
// src/lib/state/session.svelte.ts — client-side UI state only
export const ui = $state({ sidebarOpen: false });
```
- Stores from `svelte/store` still work (`writable<User | null>(null)`), but never keep per-user data in module-level state or stores in SvelteKit: on the server those modules are shared between requests. Get the user from `locals` in `load`.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
CLAUDE.md rules for React 19 with TypeScript covering typed components, derived state, compiler-aware memoization, useId-based accessibility and review checks.