Skip to content

Commit f08a4cc

Browse files
committed
address feedback
1 parent fb4ca36 commit f08a4cc

File tree

5 files changed

+8
-27
lines changed

5 files changed

+8
-27
lines changed

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ function validate_call_expression(node, scope, path) {
521521
}
522522

523523
if (rune === '$effect.root') {
524-
if (node.arguments.length < 1 || node.arguments.length > 2) {
525-
error(node, 'invalid-rune-args-length', '$effect.root', [1, 2]);
524+
if (node.arguments.length !== 1) {
525+
error(node, 'invalid-rune-args-length', '$effect.root', [1]);
526526
}
527527
}
528528
}

packages/svelte/src/internal/client/runtime.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,14 +1186,10 @@ export function user_effect(init) {
11861186

11871187
/**
11881188
* @param {() => void | (() => void)} init
1189-
* @param {() => void} [on_parent_cleanup]
11901189
* @returns {() => void}
11911190
*/
1192-
export function user_root_effect(init, on_parent_cleanup) {
1191+
export function user_root_effect(init) {
11931192
const effect = managed_render_effect(init);
1194-
if (current_effect !== null && typeof on_parent_cleanup === 'function') {
1195-
push_destroy_fn(current_effect, on_parent_cleanup);
1196-
}
11971193
return () => {
11981194
destroy_signal(effect);
11991195
};

packages/svelte/src/main/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ declare namespace $effect {
117117
*
118118
* https://svelte-5-preview.vercel.app/docs/runes#$effect-root
119119
*/
120-
export function root(fn: () => void | (() => void), fn2?: () => void): () => void;
120+
export function root(fn: () => void | (() => void)): () => void;
121121
}
122122

123123
/**

packages/svelte/tests/runtime-runes/samples/effect-root/main.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
return () => {
1414
log.push('cleanup 2') ;
1515
}
16-
}, () => {
16+
});
17+
18+
return () => {
1719
log.push('cleanup 1');
1820
nested_cleanup();
19-
});
21+
}
2022
});
2123
</script>
2224

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,6 @@ nested effects that you want to manually control. This rune also allows for crea
207207
</script>
208208
```
209209

210-
If the `$effect.root` was created within within another active effect (such as during component initialisation) then it might
211-
be desirable to know when that active effect gets disposed and cleaned up. `$effect.root` takes an optional second arugment,
212-
which is a function callback for when this happens in case. This allows you to cleanup the effect root too if needed.
213-
214-
```svelte
215-
<script>
216-
let count = $state(0);
217-
218-
const cleanup = $effect.root(() => {
219-
// ...
220-
}, () => {
221-
console.log('parent effect is cleaned up');
222-
cleanup();
223-
});
224-
</script>
225-
```
226-
227210
## `$props`
228211

229212
To declare component props, use the `$props` rune:

0 commit comments

Comments
 (0)