@@ -188,6 +188,39 @@ where
188188 }
189189}
190190
191+ #[ cfg( debug_assertions) ]
192+ thread_local ! {
193+ static RESOURCE_SOURCE_SIGNAL_ACTIVE : AtomicBool = const { AtomicBool :: new( false ) } ;
194+ }
195+
196+ #[ cfg( debug_assertions) ]
197+ /// Returns whether the current thread is currently running a resource source signal.
198+ pub fn in_resource_source_signal ( ) -> bool {
199+ RESOURCE_SOURCE_SIGNAL_ACTIVE
200+ . with ( |scope| scope. load ( std:: sync:: atomic:: Ordering :: Relaxed ) )
201+ }
202+
203+ /// Set a static to true whilst running the given function.
204+ /// [`is_in_effect_scope`] will return true whilst the function is running.
205+ fn run_in_resource_source_signal < T > ( fun : impl FnOnce ( ) -> T ) -> T {
206+ #[ cfg( debug_assertions) ]
207+ {
208+ // For the theoretical nested case, set back to initial value rather than false:
209+ let initial = RESOURCE_SOURCE_SIGNAL_ACTIVE . with ( |scope| {
210+ scope. swap ( true , std:: sync:: atomic:: Ordering :: Relaxed )
211+ } ) ;
212+ let result = fun ( ) ;
213+ RESOURCE_SOURCE_SIGNAL_ACTIVE . with ( |scope| {
214+ scope. store ( initial, std:: sync:: atomic:: Ordering :: Relaxed )
215+ } ) ;
216+ result
217+ }
218+ #[ cfg( not( debug_assertions) ) ]
219+ {
220+ fun ( )
221+ }
222+ }
223+
191224impl < T , Ser > ReadUntracked for ArcResource < T , Ser >
192225where
193226 T : ' static ,
@@ -202,7 +235,9 @@ where
202235 computed:: suspense:: SuspenseContext , effect:: in_effect_scope,
203236 owner:: use_context,
204237 } ;
205- if !in_effect_scope ( ) && use_context :: < SuspenseContext > ( ) . is_none ( )
238+ if !in_effect_scope ( )
239+ && !in_resource_source_signal ( )
240+ && use_context :: < SuspenseContext > ( ) . is_none ( )
206241 {
207242 let location = std:: panic:: Location :: caller ( ) ;
208243 reactive_graph:: log_warning ( format_args ! (
@@ -271,7 +306,7 @@ where
271306 let refetch = ArcRwSignal :: new ( 0 ) ;
272307 let source = ArcMemo :: new ( {
273308 let refetch = refetch. clone ( ) ;
274- move |_| ( refetch. get ( ) , source ( ) )
309+ move |_| ( refetch. get ( ) , run_in_resource_source_signal ( & source ) )
275310 } ) ;
276311 let fun = {
277312 let source = source. clone ( ) ;
@@ -909,7 +944,9 @@ where
909944 computed:: suspense:: SuspenseContext , effect:: in_effect_scope,
910945 owner:: use_context,
911946 } ;
912- if !in_effect_scope ( ) && use_context :: < SuspenseContext > ( ) . is_none ( )
947+ if !in_effect_scope ( )
948+ && !in_resource_source_signal ( )
949+ && use_context :: < SuspenseContext > ( ) . is_none ( )
913950 {
914951 let location = std:: panic:: Location :: caller ( ) ;
915952 reactive_graph:: log_warning ( format_args ! (
0 commit comments