File tree Expand file tree Collapse file tree 5 files changed +38
-1
lines changed
src/internal/client/reactivity
tests/runtime-runes/samples/dependencyless-abort-signal Expand file tree Collapse file tree 5 files changed +38
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: keep effect in the graph if it has an abort controller
Original file line number Diff line number Diff line change @@ -532,7 +532,9 @@ function flush_queued_effects(effects) {
532
532
// here (rather than in `update_effect`) allows us to skip the work for
533
533
// immediate effects.
534
534
if ( effect . deps === null && effect . first === null && effect . nodes_start === null ) {
535
- if ( effect . teardown === null ) {
535
+ // if there's no teardown or abort controller we completely unlink
536
+ // the effect from the graph
537
+ if ( effect . teardown === null && effect . ac === null ) {
536
538
// remove this effect from the graph
537
539
unlink_effect ( effect ) ;
538
540
} else {
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { getAbortSignal } from ' svelte' ;
3
+
4
+ $effect (() => {
5
+ const signal = getAbortSignal ()
6
+ signal .addEventListener (' abort' , () => console .log (' abort' ))
7
+ })
8
+ </script >
Original file line number Diff line number Diff line change
1
+ import { flushSync } from 'svelte' ;
2
+ import { test } from '../../test' ;
3
+
4
+ export default test ( {
5
+ async test ( { assert, target, logs } ) {
6
+ const btn = target . querySelector ( 'button' ) ;
7
+ flushSync ( ( ) => {
8
+ btn ?. click ( ) ;
9
+ } ) ;
10
+ assert . deepEqual ( logs , [ 'abort' ] ) ;
11
+ }
12
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Component from ' ./Component.svelte'
3
+
4
+ let show = $state (true )
5
+ </script >
6
+
7
+ <button onclick ={() => (show = ! show )}>click</button >
8
+ {#if show }
9
+ <Component />
10
+ {/if }
You can’t perform that action at this time.
0 commit comments