File tree Expand file tree Collapse file tree 5 files changed +38
-0
lines changed
tests/runtime-runes/samples/effect-untrack-teardown Expand file tree Collapse file tree 5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: ensure all effect cleanup functions are untracked
Original file line number Diff line number Diff line change 3
3
current_component_context ,
4
4
current_effect ,
5
5
current_reaction ,
6
+ current_untracking ,
6
7
destroy_effect_children ,
7
8
dev_current_component_function ,
8
9
execute_effect ,
@@ -14,6 +15,7 @@ import {
14
15
set_is_destroying_effect ,
15
16
set_is_flushing_effect ,
16
17
set_signal_status ,
18
+ set_untracking ,
17
19
untrack
18
20
} from '../runtime.js' ;
19
21
import {
@@ -295,11 +297,14 @@ export function execute_effect_teardown(effect) {
295
297
var teardown = effect . teardown ;
296
298
if ( teardown !== null ) {
297
299
const previously_destroying_effect = is_destroying_effect ;
300
+ const previous_untracking = current_untracking ;
298
301
set_is_destroying_effect ( true ) ;
302
+ set_untracking ( true ) ;
299
303
try {
300
304
teardown . call ( null ) ;
301
305
} finally {
302
306
set_is_destroying_effect ( previously_destroying_effect ) ;
307
+ set_untracking ( previous_untracking ) ;
303
308
}
304
309
}
305
310
}
Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ export function set_is_destroying_effect(value) {
48
48
is_destroying_effect = value ;
49
49
}
50
50
51
+ /** @param {boolean } value */
52
+ export function set_untracking ( value ) {
53
+ current_untracking = value ;
54
+ }
55
+
51
56
// Used for $inspect
52
57
export let is_batching_effect = false ;
53
58
let is_inspecting_signal = false ;
Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+
3
+ // nothing to test here — if the teardown function is not untracked, effect will loop
4
+ export default test ( { } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let prop = $state ();
3
+ let key = $state ({});
4
+
5
+ function action () {
6
+ prop = {};
7
+ $effect .pre (() => {
8
+ return () => {
9
+ prop;
10
+ }
11
+ });
12
+ }
13
+
14
+ $effect (() => key = {});
15
+ </script >
16
+
17
+ {#key key }
18
+ <div use:action >test</div >
19
+ {/ key }
You can’t perform that action at this time.
0 commit comments