소스 검색

extend the subscriber list instead of overriding it; fixes subscribers added in mark_dirty (#2319)

Evan Almloff 1 년 전
부모
커밋
61360ea05f
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      packages/signals/src/signal.rs

+ 2 - 1
packages/signals/src/signal.rs

@@ -155,7 +155,8 @@ impl<T: 'static, S: Storage<SignalData<T>>> Signal<T, S> {
             // We cannot hold the subscribers lock while calling mark_dirty, because mark_dirty can run user code which may cause a new subscriber to be added. If we hold the lock, we will deadlock.
             let mut subscribers = std::mem::take(&mut *inner.subscribers.lock().unwrap());
             subscribers.retain(|reactive_context| reactive_context.mark_dirty());
-            *inner.subscribers.lock().unwrap() = subscribers;
+            // Extend the subscribers list instead of overwriting it in case a subscriber is added while reactive contexts are marked dirty
+            inner.subscribers.lock().unwrap().extend(subscribers);
         }
     }