浏览代码

Fix write on render warning with read only signal props (#3194)

Evan Almloff 7 月之前
父节点
当前提交
21465390f8
共有 3 个文件被更改,包括 10 次插入4 次删除
  1. 3 2
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 6 1
      packages/signals/src/read_only_signal.rs

+ 3 - 2
Cargo.lock

@@ -12371,11 +12371,12 @@ dependencies = [
 
 [[package]]
 name = "warnings"
-version = "0.2.0"
+version = "0.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0c672c7629eeed21c37d7a96ee9c0287b86a5e29b5730773117e4261d1a73ca"
+checksum = "64f68998838dab65727c9b30465595c6f7c953313559371ca8bf31759b3680ad"
 dependencies = [
  "pin-project",
+ "tracing",
  "warnings-macro",
 ]
 

+ 1 - 1
Cargo.toml

@@ -142,7 +142,7 @@ manganis = { path = "packages/manganis/manganis", version = "0.6.0-alpha.4" }
 manganis-core = { path = "packages/manganis/manganis-core", version = "0.6.0-alpha.4" }
 manganis-macro = { path = "packages/manganis/manganis-macro", version = "0.6.0-alpha.4" }
 
-warnings = { version = "0.2.0" }
+warnings = { version = "0.2.1" }
 
 
 # a fork of pretty please for tests - let's get off of this if we can!

+ 6 - 1
packages/signals/src/read_only_signal.rs

@@ -52,7 +52,12 @@ impl<T: 'static, S: Storage<SignalData<T>>> ReadOnlySignal<T, S> {
     /// Mark any readers of the signal as dirty
     pub fn mark_dirty(&mut self) {
         use crate::write::Writable;
-        _ = self.inner.try_write();
+        use warnings::Warning;
+        // We diff props while rendering, but we only write to the signal if it has
+        // changed so it is safe to ignore the warning
+        crate::warnings::signal_write_in_component_body::allow(|| {
+            _ = self.inner.try_write();
+        });
     }
 }