Browse Source

fix infinite recursion in reactive context

Evan Almloff 1 year ago
parent
commit
26e4651e9f
2 changed files with 7 additions and 4 deletions
  1. 5 2
      packages/signals/src/rc.rs
  2. 2 2
      packages/signals/src/rt.rs

+ 5 - 2
packages/signals/src/rc.rs

@@ -19,7 +19,7 @@ pub struct ReactiveContext {
 }
 
 thread_local! {
-    static CURRENT: RefCell<Vec<ReactiveContext>> = RefCell::new(vec![]);
+    static CURRENT: RefCell<Vec<ReactiveContext>> = const { RefCell::new(vec![]) };
 }
 
 impl ReactiveContext {
@@ -42,7 +42,10 @@ impl ReactiveContext {
         };
 
         let mut self_ = Self {
-            inner: CopyValue::new_maybe_sync(inner),
+            inner: CopyValue::new_maybe_sync_in_scope(
+                inner,
+                scope.or_else(current_scope_id).unwrap(),
+            ),
         };
 
         self_.inner.write().self_ = Some(self_);

+ 2 - 2
packages/signals/src/rt.rs

@@ -55,8 +55,8 @@ fn set_owner<S: AnyStorage>(owner: Option<Owner<S>>) -> Option<Owner<S>> {
 }
 
 thread_local! {
-    static SYNC_OWNER: RefCell<Option<Owner<SyncStorage>>> = RefCell::new(None);
-    static UNSYNC_OWNER: RefCell<Option<Owner<UnsyncStorage>>> = RefCell::new(None);
+    static SYNC_OWNER: RefCell<Option<Owner<SyncStorage>>> = const { RefCell::new(None) };
+    static UNSYNC_OWNER: RefCell<Option<Owner<UnsyncStorage>>> = const { RefCell::new(None) };
 }
 
 fn current_owner<S: Storage<T>, T>() -> Owner<S> {