Compare commits

...

2 Commits

Author SHA1 Message Date
Greg Johnston d5ad8f5ae4 fix: don't disable non-reactive access warnings at component body level 2023-07-03 16:13:45 -04:00
Greg Johnston 6b3e9cf85f fix: improve diagnostics for untracked reads on `create_slice` 2023-07-03 16:09:32 -04:00
4 changed files with 26 additions and 7 deletions

View File

@ -271,8 +271,9 @@ where
let mut repr = ComponentRepr::new_with_id(name, id);
// disposed automatically when the parent scope is disposed
let (child, _) = cx
.run_child_scope(|cx| cx.untrack(|| children_fn(cx).into_view(cx)));
let (child, _) = cx.run_child_scope(|cx| {
cx.untrack_with_diagnostics(|| children_fn(cx).into_view(cx))
});
repr.children.push(child);

View File

@ -479,11 +479,17 @@ impl RuntimeId {
instrument(level = "trace", skip_all,)
)]
#[inline(always)]
pub(crate) fn untrack<T>(self, f: impl FnOnce() -> T) -> T {
pub(crate) fn untrack<T>(
self,
f: impl FnOnce() -> T,
diagnostics: bool,
) -> T {
with_runtime(self, |runtime| {
let untracked_result;
if !diagnostics {
SpecialNonReactiveZone::enter();
}
let prev_observer =
SetObserverOnDrop(self, runtime.observer.take());
@ -493,7 +499,9 @@ impl RuntimeId {
runtime.observer.set(prev_observer.1);
std::mem::forget(prev_observer); // avoid Drop
if !diagnostics {
SpecialNonReactiveZone::exit();
}
untracked_result
})
@ -758,7 +766,7 @@ impl RuntimeId {
cur_deps_value.replace(Some(deps_value.clone()));
let callback_value =
Some(self.untrack(wrapped_callback.clone()));
Some(self.untrack(wrapped_callback.clone(), false));
prev_callback_value.replace(callback_value);

View File

@ -208,7 +208,14 @@ impl Scope {
)]
#[inline(always)]
pub fn untrack<T>(&self, f: impl FnOnce() -> T) -> T {
self.runtime.untrack(f)
self.runtime.untrack(f, false)
}
#[doc(hidden)]
/// Suspends reactive tracking but keeps the diagnostic warnings for
/// untracked functions.
pub fn untrack_with_diagnostics<T>(&self, f: impl FnOnce() -> T) -> T {
self.runtime.untrack(f, true)
}
}

View File

@ -68,6 +68,7 @@ use crate::{
/// // setting name only causes name to log, not count
/// set_name.set("Bob".into());
/// ```
#[track_caller]
pub fn create_slice<T, O, S>(
cx: Scope,
signal: RwSignal<T>,
@ -85,6 +86,7 @@ where
/// Takes a memoized, read-only slice of a signal. This is equivalent to the
/// read-only half of [`create_slice`].
#[track_caller]
pub fn create_read_slice<T, O>(
cx: Scope,
signal: RwSignal<T>,
@ -98,6 +100,7 @@ where
/// Creates a setter to access one slice of a signal. This is equivalent to the
/// write-only half of [`create_slice`].
#[track_caller]
pub fn create_write_slice<T, O>(
cx: Scope,
signal: RwSignal<T>,