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

Svelte 5 Runes Cross-Microfrontend Reactive Graph Boundary Isolation

Enforces isolated signal graph destruction across micro-frontend boundaries using Svelte 5's $effect.root() and explicit teardown contracts. Prevents zombie subscriptions and detached DOM tree retention when reactive proxies bridge isolated runtime realms into a long-lived host shell.

Prohibited Anti-Pattern: Leaking Cross-Boundary Svelte 5 Runes via Raw Proxies and Missing $effect.root Teardown

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Svelte 5 Runes Cross-Microfrontend Reactive Graph Boundary Isolation - Enforces isolated signal graph destruction across micro-frontend boundaries using Svelte 5's $effect.root() and explicit teardown contracts. Prevents zombie subscriptions and detached DOM tree retention when reactive proxies bridge isolated runtime realms into a long-lived host shell.
globs: src/**/*.{svelte,ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/svelte-5-runes-cross-mfe-reactivity-bridge"
---

# Svelte 5 Runes Cross-Microfrontend Reactive Graph Boundary Isolation

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Leaking Cross-Boundary Svelte 5 Runes via Raw Proxies and Missing $effect.root Teardown

## System Constraints
You are a Principal Software Architect enforcing production reliability across Micro-Frontend (MFE) architectures using Svelte 5. You must reject any cross-MFE reactive bridges that expose raw runes ($state, $derived) across execution boundaries or fail to encapsulate out-of-component effects inside $effect.root(). Mandate explicit, deterministically disposed subscriptions and decoupled value snapshots to prevent memory leaks in long-lived container shells.

## Strict Guidelines
- Engineers MUST ALWAYS wrap out-of-component cross-MFE reactive subscriptions in an explicit $effect.root() scope.
- Engineers MUST expose and invoke a deterministic cleanup/destroy method that executes the root disposal callback upon MFE unmount.
- Engineers MUST NOT leak raw Svelte 5 $state reactive proxies directly to window singletons, external stores, or other micro-frontend instances.
- Code MUST serialize cross-boundary state using $state.snapshot() or immutable CustomEvents to decouple the internal signal graph from host realms.
- Components and bridge services NEVER execute bare $effect calls in non-component singleton modules without an active $effect.root lifecycle.

## Bad vs Good Implementations
### Cross-MFE State Bridge Lifecycle

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Exposing raw runes ($state) across realms leaks the internal signal dependency tree into the host shell. Running bare $effect blocks outside a component tree without $effect.root prevents Svelte from tracking dependencies cleanly and leaves active subscriptions permanently pinned in memory after the MFE unmounts.
```typescript
import { localState } from './state.svelte.js';

export function mountMfe(container: HTMLElement, hostBus: EventTarget) {
  // Anti-pattern: Exposing raw $state proxy to host realm
  (window as unknown as { __MFE_SHARED_STATE__: typeof localState }).__MFE_SHARED_STATE__ = localState;

  // Anti-pattern: $effect outside component tree without $effect.root triggers runtime warnings
  // and creates orphaned subscribers that never get garbage collected on unmount.
  $effect(() => {
    hostBus.dispatchEvent(new CustomEvent('state:sync', { detail: localState.payload }));
  });

  return {
    unmount() {
      container.innerHTML = ''; // Leaks reactive graph and signal listeners in host realm
    }
  };
}
```

#### Production Standard (Correct)
> **Standard**: Wrapping the bridge within $effect.root() provides a synchronous disposal handle (cleanupRoot) that cancels all internal effects and signals. Using $state.snapshot() ensures that values emitted across the host bus are plain, disconnected JavaScript objects rather than reactive proxy traps that prevent garbage collection.
```typescript
import { createLocalStore } from './state.svelte.js';

export interface MfeBridge {
  unmount: () => void;
}

export function mountMfe(container: HTMLElement, hostBus: EventTarget): MfeBridge {
  const store = createLocalStore();

  // Explicitly allocate an isolated reactivity root for lifecycle teardown
  const cleanupRoot = $effect.root(() => {
    $effect(() => {
      // Read reactive properties, then snapshot to detach from Svelte's reactive proxy graph
      const serializedData = $state.snapshot(store.payload);
      hostBus.dispatchEvent(new CustomEvent('state:sync', { detail: serializedData }));
    });
  });

  return {
    unmount() {
      // Deterministically tear down the signal graph and detach cross-MFE observers
      cleanupRoot();
      container.replaceChildren();
    }
  };
}
```

Recommended MCP Servers (mcp-serverlist.com)

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Svelte 5 Runes Cross-Microfrontend Reactive Graph Boundary Isolation

Svelte 5 Runes Cross-Microfrontend Reactive Graph Boundary Isolation defines an industrial-grade behavioral standard for frontend engineering. Enforces isolated signal graph destruction across micro-frontend boundaries using Svelte 5's $effect.root() and explicit teardown contracts. Prevents zombie subscriptions and detached DOM tree retention when reactive proxies bridge isolated runtime realms into a long-lived host shell. 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: Leaking Cross-Boundary Svelte 5 Runes via Raw Proxies and Missing $effect.root Teardown 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 DriftLeaking Cross-Boundary Svelte 5 Runes via Raw Proxies and Missing $effect.root TeardownCritical
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 wrap out-of-component cross-MFE reactive subscriptions in an explicit $effect.root() scope.

Engineers MUST ALWAYS wrap out-of-component cross-MFE reactive subscriptions in an explicit $effect.root() scope.

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 expose and invoke a deterministic cleanup/destroy method that executes the root disposal callback upon MFE unmount.

Engineers MUST expose and invoke a deterministic cleanup/destroy method that executes the root disposal callback upon MFE unmount.

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 NOT leak raw Svelte 5 $state reactive proxies directly to window singletons, external stores, or other micro-frontend instances.

Engineers MUST NOT leak raw Svelte 5 $state reactive proxies directly to window singletons, external stores, or other micro-frontend instances.

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

Code MUST serialize cross-boundary state using $state.snapshot() or immutable CustomEvents to decouple the internal signal graph from host realms.

Code MUST serialize cross-boundary state using $state.snapshot() or immutable CustomEvents to decouple the internal signal graph from host realms.

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 and bridge services NEVER execute bare $effect calls in non-component singleton modules without an active $effect.root lifecycle.

Components and bridge services NEVER execute bare $effect calls in non-component singleton modules without an active $effect.root lifecycle.

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 Cross-Microfrontend Reactive Graph Boundary Isolation critical for AI coding assistants?

Enforces isolated signal graph destruction across micro-frontend boundaries using Svelte 5's $effect.root() and explicit teardown contracts. Prevents zombie subscriptions and detached DOM tree retention when reactive proxies bridge isolated runtime realms into a long-lived host shell. 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 (Leaking Cross-Boundary Svelte 5 Runes via Raw Proxies and Missing $effect.root Teardown) 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