diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index a5b8f66b57..700ec21e19 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -176,8 +176,6 @@ const runes = { 'invalid-state-location': () => `$state() can only be used as a variable declaration initializer or a class field`, 'invalid-effect-location': () => `$effect() can only be used as an expression statement`, - 'invalid-effect-root-location': () => - `$effect.root() can only be used as a variable declaration initializer`, /** * @param {boolean} is_binding * @param {boolean} show_details diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index c823f50c36..c95fb5894d 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -524,8 +524,6 @@ function validate_call_expression(node, scope, path) { if (node.arguments.length < 1 || node.arguments.length > 2) { error(node, 'invalid-rune-args-length', '$effect.root', [1, 2]); } - if (parent.type === 'VariableDeclarator') return; - error(node, 'invalid-effect-root-location'); } } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js index 34f8c5e579..f3b0d2b908 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js @@ -135,7 +135,7 @@ export const javascript_visitors_runes = { for (const declarator of node.declarations) { const init = declarator.init; const rune = get_rune(init, state.scope); - if (!rune || rune === '$effect.active') { + if (!rune || rune === '$effect.active' || rune === '$effect.root') { if (init != null && is_hoistable_function(init)) { const hoistable_function = visit(init); state.hoisted.push( @@ -209,17 +209,6 @@ export const javascript_visitors_runes = { continue; } const args = /** @type {import('estree').CallExpression} */ (declarator.init).arguments; - - if (rune === '$effect.root') { - const serialized_args = /** @type {import('estree').Expression[]} */ ( - args.map((arg) => visit(arg)) - ); - declarations.push( - b.declarator(declarator.id, b.call('$.user_root_effect', ...serialized_args)) - ); - continue; - } - const value = args.length === 0 ? b.id('undefined') diff --git a/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md b/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md index a2de65b839..78095c4cb0 100644 --- a/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md +++ b/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md @@ -191,8 +191,6 @@ This allows you to (for example) add things like subscriptions without causing m The `$effect.root` rune is an advanced feature that creates a non-tracked scope that doesn't auto-cleanup. This is useful for nested effects that you want to manually control. This rune also allows for creation of effects outside of the component initialisation phase. -> `$effect.root` can only be used in variable declaration initializer, this is to ensure the return signature (the cleanup function) is always used. - ```svelte