@@ -419,10 +419,15 @@ function remove_reaction(signal, dependency) {
419
419
export function remove_reactions ( signal , start_index ) {
420
420
const dependencies = signal . deps ;
421
421
if ( dependencies !== null ) {
422
- const active_dependencies = start_index === 0 ? null : dependencies . slice ( 0 , start_index ) ;
422
+ var active_dependencies = start_index === 0 ? null : dependencies . slice ( 0 , start_index ) ;
423
+ var visited = new Set ( ) ;
423
424
let i ;
424
425
for ( i = start_index ; i < dependencies . length ; i ++ ) {
425
426
const dependency = dependencies [ i ] ;
427
+ if ( visited . has ( dependency ) ) {
428
+ continue ;
429
+ }
430
+ visited . add ( dependency ) ;
426
431
// Avoid removing a reaction if we know that it is active (start_index will not be 0)
427
432
if ( active_dependencies === null || ! active_dependencies . includes ( dependency ) ) {
428
433
remove_reaction ( signal , dependency ) ;
@@ -774,10 +779,7 @@ export function get(signal) {
774
779
) {
775
780
if ( current_dependencies === null ) {
776
781
current_dependencies = [ signal ] ;
777
- } else if (
778
- current_dependencies [ current_dependencies . length - 1 ] !== signal &&
779
- ! current_dependencies . includes ( signal )
780
- ) {
782
+ } else if ( current_dependencies [ current_dependencies . length - 1 ] !== signal ) {
781
783
current_dependencies . push ( signal ) ;
782
784
}
783
785
}
0 commit comments