fix: improvements "untracked read" warnings in untrack, SSR cases (#791)

This commit is contained in:
Greg Johnston 2023-04-02 15:57:06 -04:00 committed by GitHub
parent 4c23f3c478
commit 8bdb427133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -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)]
{

View file

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

View file

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