Skip to main content
Glama

MCP Svelte Docs Server

# $effect.root Definition **Definition:** Creates a non-tracked scope that doesn't auto-cleanup **Syntax:** `$effect.root(fn: () => void | (() => void)): () => void` **Parameters:** - `fn` - Function to run, optionally returns cleanup function **Returns:** Cleanup function to manually destroy the effect root **Variants:** - Part of `$effect` rune family ## Examples ```js // Create manually controlled effect scope const destroy = $effect.root(() => { $effect(() => { console.log('This effect runs inside the root'); }); return () => { console.log('Effect root cleanup'); }; }); // Later, manually cleanup destroy(); // Creating effects outside component initialization let count = $state(0); const cleanup = $effect.root(() => { $effect(() => { console.log('Count changed:', count); }); return () => { console.log('Cleaning up count watcher'); }; }); // Cleanup when needed function stopWatching() { cleanup(); } ``` ## Related - `$effect` - For regular effects with auto-cleanup - `$effect.pre` - For effects that run before DOM updates - `$state` - For reactive state that can trigger effects

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/spences10/mcp-svelte-docs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server