Merge pull request #2222 from leptos-rs/2221

fix: `.refetch()` should not include any tracked reads
This commit is contained in:
Greg Johnston 2024-01-24 20:44:51 -05:00 committed by GitHub
commit 936c2077c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 4 deletions

View file

@ -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;

View file

@ -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()

View file

@ -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,
@ -244,6 +244,7 @@ where
create_isomorphic_effect({
let r = Rc::clone(&r);
move |_| {
source.track();
load_resource(id, r.clone());
}
});
@ -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