Переглянути джерело

Ignore write while rendering warning in memo lazy recompute (#3647)

Evan Almloff 5 місяців тому
батько
коміт
c85018300b
1 змінених файлів з 5 додано та 1 видалено
  1. 5 1
      packages/signals/src/memo.rs

+ 5 - 1
packages/signals/src/memo.rs

@@ -1,3 +1,4 @@
+use crate::warnings::{signal_read_and_write_in_reactive_scope, signal_write_in_component_body};
 use crate::write::Writable;
 use crate::write::Writable;
 use crate::{read::Readable, ReadableRef, Signal};
 use crate::{read::Readable, ReadableRef, Signal};
 use crate::{read_impls, GlobalMemo};
 use crate::{read_impls, GlobalMemo};
@@ -11,6 +12,7 @@ use std::{
 use dioxus_core::prelude::*;
 use dioxus_core::prelude::*;
 use futures_util::StreamExt;
 use futures_util::StreamExt;
 use generational_box::{AnyStorage, BorrowResult, UnsyncStorage};
 use generational_box::{AnyStorage, BorrowResult, UnsyncStorage};
+use warnings::Warning;
 
 
 struct UpdateInformation<T> {
 struct UpdateInformation<T> {
     dirty: Arc<AtomicBool>,
     dirty: Arc<AtomicBool>,
@@ -179,7 +181,9 @@ where
         let result = if needs_update {
         let result = if needs_update {
             drop(read);
             drop(read);
             // We shouldn't be subscribed to the value here so we don't trigger the scope we are currently in to rerun even though that scope got the latest value because we synchronously update the value: https://github.com/DioxusLabs/dioxus/issues/2416
             // We shouldn't be subscribed to the value here so we don't trigger the scope we are currently in to rerun even though that scope got the latest value because we synchronously update the value: https://github.com/DioxusLabs/dioxus/issues/2416
-            self.recompute();
+            signal_read_and_write_in_reactive_scope::allow(|| {
+                signal_write_in_component_body::allow(|| self.recompute())
+            });
             self.inner.inner.try_read_unchecked()
             self.inner.inner.try_read_unchecked()
         } else {
         } else {
             Ok(read)
             Ok(read)