@@ -34,6 +34,18 @@ impl<T> Signal<T> {
3434
3535 /// Runs all dependent effects.
3636 fn flush_effects ( & self ) {
37+ // When triggering an Effect, dependencies are not collected for that Effect.
38+ //
39+ // The issue arises from the creation of Effect A, which may trigger Effect B.
40+ // In Effect B, the signal get operation causes incorrect tracking of Effect A.
41+ // In this case, dependency tracking for Effect A should not be performed
42+ // until Effect B exits the triggering phase.
43+ //
44+ // The root cause of this issue is a temporary violation of the assumption that
45+ // "an Effect is always the end point of the call chain."
46+ let creating_effect = unsafe { crate :: call_stack:: CREATING_EFFECT } ;
47+ unsafe { crate :: call_stack:: CREATING_EFFECT = false } ;
48+
3749 self . effects . borrow_mut ( ) . retain ( |w| {
3850 if let Some ( e) = w. upgrade ( ) {
3951 e. run ( ) ;
@@ -42,6 +54,8 @@ impl<T> Signal<T> {
4254 false
4355 }
4456 } ) ;
57+
58+ unsafe { crate :: call_stack:: CREATING_EFFECT = creating_effect } ;
4559 }
4660
4761 #[ allow( non_snake_case) ]
@@ -103,7 +117,8 @@ impl<T> Signal<T> {
103117 }
104118
105119 // Track effects in the call stack
106- if let Some ( e) = call_stack:: current_effect_peak ( )
120+ if unsafe { call_stack:: CREATING_EFFECT }
121+ && let Some ( e) = call_stack:: current_effect_peak ( )
107122 && !self . effects . borrow ( ) . iter ( ) . any ( |w| Weak :: ptr_eq ( w, & e) )
108123 {
109124 self . effects . borrow_mut ( ) . push ( e) ;
0 commit comments