mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
fix: improvements "untracked read" warnings in untrack
, SSR cases (#791)
This commit is contained in:
parent
4c23f3c478
commit
8bdb427133
3 changed files with 8 additions and 2 deletions
|
@ -5,6 +5,7 @@ use cfg_if::cfg_if;
|
|||
// you create a signal/memo, and where you access it non-reactively.
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[allow(dead_code)] // allowed for SSR
|
||||
#[derive(Copy, Clone)]
|
||||
pub(crate) struct AccessDiagnostics {
|
||||
pub defined_at: &'static std::panic::Location<'static>,
|
||||
|
@ -33,6 +34,7 @@ cfg_if! {
|
|||
}
|
||||
|
||||
impl SpecialNonReactiveZone {
|
||||
#[allow(dead_code)] // allowed for SSR
|
||||
pub(crate) fn is_inside() -> bool {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
|
|
@ -5,7 +5,8 @@ use crate::{
|
|||
node::NodeId,
|
||||
runtime::{with_runtime, RuntimeId},
|
||||
suspense::StreamChunk,
|
||||
PinnedFuture, ResourceId, StoredValueId, SuspenseContext,
|
||||
PinnedFuture, ResourceId, SpecialNonReactiveZone, StoredValueId,
|
||||
SuspenseContext,
|
||||
};
|
||||
use futures::stream::FuturesUnordered;
|
||||
use std::{
|
||||
|
@ -176,9 +177,11 @@ impl Scope {
|
|||
/// ```
|
||||
pub fn untrack<T>(&self, f: impl FnOnce() -> T) -> T {
|
||||
with_runtime(self.runtime, |runtime| {
|
||||
SpecialNonReactiveZone::enter();
|
||||
let prev_observer = runtime.observer.take();
|
||||
let untracked_result = f();
|
||||
runtime.observer.set(prev_observer);
|
||||
SpecialNonReactiveZone::exit();
|
||||
untracked_result
|
||||
})
|
||||
.expect(
|
||||
|
|
|
@ -771,6 +771,7 @@ where
|
|||
|
||||
/// Applies the function to the current Signal, if it exists, and subscribes
|
||||
/// the running effect.
|
||||
#[track_caller]
|
||||
pub(crate) fn try_with<U>(
|
||||
&self,
|
||||
f: impl FnOnce(&T) -> U,
|
||||
|
@ -1828,7 +1829,7 @@ impl NodeId {
|
|||
sources.borrow_mut().insert(*self);
|
||||
}
|
||||
} else {
|
||||
#[cfg(debug_assertions)]
|
||||
#[cfg(all(debug_assertions, not(feature = "ssr")))]
|
||||
{
|
||||
if !SpecialNonReactiveZone::is_inside() {
|
||||
let AccessDiagnostics {
|
||||
|
|
Loading…
Reference in a new issue