This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
frontendcritical PriorityID: svelte-5-runes-reactivity-and-snippets-standard

Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition

Enforces architectural invariants for Svelte 5 runes ($state, $derived, $props, $effect) and snippet composition. Prevents reactivity severing caused by destructuring reactive proxies, completely eliminates legacy Svelte 3/4 reactivity paradigms (export let, $:, <slot />), and bans side-effect synchronization antipatterns in $effect.

Prohibited Anti-Pattern: Reactivity severing through proxy destructuring and derived-state synchronization inside $effect

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition - Enforces architectural invariants for Svelte 5 runes ($state, $derived, $props, $effect) and snippet composition. Prevents reactivity severing caused by destructuring reactive proxies, completely eliminates legacy Svelte 3/4 reactivity paradigms (export let, $:, <slot />), and bans side-effect synchronization antipatterns in $effect.
globs: src/**/*.svelte, src/**/*.svelte.ts, src/**/*.svelte.js, src/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/svelte-5-runes-reactivity-and-snippets-standard"
---

# Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Reactivity severing through proxy destructuring and derived-state synchronization inside $effect

## System Constraints
You are a Principal Software Architect enforcing Svelte 5 Runes standards. Svelte 5 completely deprecates the compiler-driven let/export/$: reactivity model in favor of fine-grained signal proxies ($state, $derived, $props, $effect) and programmatic snippets. You MUST mandate strict adherence to rune semantics, prevent reactivity stripping via premature destructuring, and eradicate legacy slot or reactive assignment patterns.

## Strict Guidelines
- Engineers MUST ALWAYS use $props() for component interface definitions and MUST NOT use legacy 'export let' syntax.
- Engineers MUST NEVER destructure properties directly from a mutable $state object if reactivity across property updates is required; access properties directly via the proxy reference.
- Engineers MUST NEVER use $effect() to synchronize state that can be computed synchronously; use $derived() or $derived.by() instead.
- Engineers MUST encapsulate shared reactive logic in '.svelte.ts' or '.svelte.js' module files using runes, never in plain '.ts' files relying on store subscriptions.
- Components NEVER use legacy <slot /> or <svelte:fragment> syntax; snippet composition using '{#snippet name(args)}' and '{@render name(args)}' MUST be used exclusively.
- Code MUST use $state.raw() for large immutable collections, third-party class instances, or complex objects that do not require deep fine-grained proxy wrapping.
- Engineers MUST ensure cleanup functions returned from $effect() are idempotent and free of secondary reactive mutations that cause infinite loops.

## Bad vs Good Implementations
### State Derivation and Proxy Preservation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Destructuring `profile` disconnects `name` and `loginCount` from the underlying Svelte proxy, freezing their values. Using `$effect` to write to another `$state` variable causes dual-cycle updates, breaks synchronous consistency, and causes unnecessary renders.
```typescript
import { untrack } from 'svelte';

// Anti-pattern: Destructuring reactive proxy breaks mutation tracking,
// and using $effect to mirror state leads to redundant render cascades.
interface UserProfile {
  name: string;
  loginCount: number;
}

let profile = $state<UserProfile>({ name: 'Ada', loginCount: 1 });
// Destructuring breaks reactivity; 'name' is now an immutable primitive copy:
let { name, loginCount } = profile;

let isReturningUser = $state(false);
// Slower, prone to infinite loops and flash of uncomputed state:
$effect(() => {
  isReturningUser = loginCount > 0;
});
```

#### Production Standard (Correct)
> **Standard**: Preserving the `profile` proxy ensures fine-grained subscriptions track mutations accurately. Replacing the `$effect` with `$derived` guarantees synchronous purity, optimal dependency tracking, and avoids cascade cycles.
```typescript
interface UserProfile {
  name: string;
  loginCount: number;
}

// Production standard: Keep proxy intact and compute synchronously via $derived
const profile = $state<UserProfile>({ name: 'Ada', loginCount: 1 });

// Explicit derived state computed synchronously without effect scheduling
const isReturningUser = $derived(profile.loginCount > 0);

// Direct property access preserves fine-grained dependency tracking
export function updateName(newName: string): void {
  profile.name = newName;
}
```

### Component Props Contract with Snippet Composition

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using `export let` and `$:` is legacy Svelte 3/4 syntax that breaks interoperability in Svelte 5 runes mode and impedes static type inference with TypeScript.
```typescript
// Bad: Mixing legacy props with $state or attempting to mutate immutable incoming props directly
interface Props {
  userId: string;
  initialFilter?: string;
}

// Incorrect legacy syntax combined with anti-pattern mutation
export let userId: string;
export let initialFilter: string = 'all';

$: normalizedFilter = initialFilter.toLowerCase();
```

#### Production Standard (Correct)
> **Standard**: The `$props()` rune correctly types and declares incoming component inputs. Snippets replace legacy slots for explicit, typed template rendering with parameter passing.
```typescript
import type { Snippet } from 'svelte';

interface Props {
  userId: string;
  initialFilter?: string;
  header?: Snippet<[{ title: string }]>;
  children?: Snippet;
}

// Production standard: $props() rune with type checking, destructuring, and snippets
const { 
  userId, 
  initialFilter = 'all', 
  header, 
  children 
}: Props = $props();

const normalizedFilter = $derived(initialFilter.toLowerCase());
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition

Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition defines an industrial-grade behavioral standard for frontend engineering. Enforces architectural invariants for Svelte 5 runes ($state, $derived, $props, $effect) and snippet composition. Prevents reactivity severing caused by destructuring reactive proxies, completely eliminates legacy Svelte 3/4 reactivity paradigms (export let, $:, <slot />), and bans side-effect synchronization antipatterns in $effect. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Reactivity severing through proxy destructuring and derived-state synchronization inside $effect Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftReactivity severing through proxy destructuring and derived-state synchronization inside $effectCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS use $props() for component interface definitions and MUST NOT use legacy 'export let' syntax.

Engineers MUST ALWAYS use $props() for component interface definitions and MUST NOT use legacy 'export let' syntax.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NEVER destructure properties directly from a mutable $state object if reactivity across property updates is required

Engineers MUST NEVER destructure properties directly from a mutable $state object if reactivity across property updates is required; access properties directly via the proxy reference.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NEVER use $effect() to synchronize state that can be computed synchronously

Engineers MUST NEVER use $effect() to synchronize state that can be computed synchronously; use $derived() or $derived.by() instead.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Engineers MUST encapsulate shared reactive logic in '.svelte.ts' or '.svelte.js' module files using runes, never in plain '.ts' files relying on store subscriptions.

Engineers MUST encapsulate shared reactive logic in '.svelte.ts' or '.svelte.js' module files using runes, never in plain '.ts' files relying on store subscriptions.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER use legacy <slot /> or <svelte

Components NEVER use legacy <slot /> or <svelte:fragment> syntax; snippet composition using '{#snippet name(args)}' and '{@render name(args)}' MUST be used exclusively.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Code MUST use $state.raw() for large immutable collections, third-party class instances, or complex objects that do not require deep fine-grained proxy wrapping.

Code MUST use $state.raw() for large immutable collections, third-party class instances, or complex objects that do not require deep fine-grained proxy wrapping.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
7

Engineers MUST ensure cleanup functions returned from $effect() are idempotent and free of secondary reactive mutations that cause infinite loops.

Engineers MUST ensure cleanup functions returned from $effect() are idempotent and free of secondary reactive mutations that cause infinite loops.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Svelte 5 Runes Invariant: Fine-Grained Reactivity and Snippet Composition critical for AI coding assistants?

Enforces architectural invariants for Svelte 5 runes ($state, $derived, $props, $effect) and snippet composition. Prevents reactivity severing caused by destructuring reactive proxies, completely eliminates legacy Svelte 3/4 reactivity paradigms (export let, $:, <slot />), and bans side-effect synchronization antipatterns in $effect. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Reactivity severing through proxy destructuring and derived-state synchronization inside $effect) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

Svelte