Skip to content

Commit

Permalink
Merge pull request #2222 from leptos-rs/2221
Browse files Browse the repository at this point in the history
fix: `.refetch()` should not include any tracked reads
  • Loading branch information
gbj authored Jan 25, 2024
2 parents fce2c72 + b3b1887 commit 936c207
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![forbid(unsafe_code)]
// to prevent warnings from popping up when a nightly feature is stabilized
#![allow(stable_features)]
// FIXME? every use of quote! {} is warning here -- false positive?
#![allow(unknown_lints)]
#![allow(private_macro_use)]

#[macro_use]
extern crate proc_macro_error;
Expand Down
7 changes: 6 additions & 1 deletion leptos_reactive/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ impl<T> SignalWithUntracked for Memo<T> {
#[inline]
fn try_with_untracked<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O> {
with_runtime(|runtime| {
self.id.try_with_no_subscription(runtime, |v: &T| f(v)).ok()
self.id
.try_with_no_subscription(runtime, |v: &Option<T>| {
v.as_ref().map(f)
})
.ok()
.flatten()
})
.ok()
.flatten()
Expand Down
7 changes: 4 additions & 3 deletions leptos_reactive/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
signal_prelude::format_signal_warning, spawn::spawn_local,
suspense::LocalStatus, use_context, GlobalSuspenseContext, Memo,
ReadSignal, ScopeProperty, Signal, SignalDispose, SignalGet,
SignalGetUntracked, SignalSet, SignalUpdate, SignalWith, SuspenseContext,
WriteSignal,
SignalGetUntracked, SignalSet, SignalUpdate, SignalWith,
SignalWithUntracked, SuspenseContext, WriteSignal,
};
use std::{
any::Any,
Expand Down Expand Up @@ -244,6 +244,7 @@ where
create_isomorphic_effect({
let r = Rc::clone(&r);
move |_| {
source.track();
load_resource(id, r.clone());
}
});
Expand Down Expand Up @@ -1358,7 +1359,7 @@ where
self.version.set(version);
self.scheduled.set(false);

_ = self.source.try_with(|source| {
_ = self.source.try_with_untracked(|source| {
let fut = (self.fetcher)(source.clone());

// `scheduled` is true for the rest of this code only
Expand Down

0 comments on commit 936c207

Please sign in to comment.