tqwewe / leptos_server_signal

Leptos server signals synced through websockets
MIT License
58 stars 11 forks source link

Lots of accessing a signal or memo outside a reactive tracking context warnings #7

Closed messense closed 1 year ago

messense commented 1 year ago

In Chrome console:

example.js:461 At /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_server_signal-0.5.0/src/lib.rs:141:85, you access a signal or memo (defined at /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_server_signal-0.5.0/src/lib.rs:127:40) outside a reactive tracking context. This might mean your app is not responding to changes in signal values in the way you expect.

Here’s how to fix it:

1. If this is inside a `view!` macro, make sure you are passing a function, not a value.
  ❌ NO  <p>{x.get() * 2}</p>
  ✅ YES <p>{move || x.get() * 2}</p>

2. If it’s in the body of a component, try wrapping this access in a closure: 
  ❌ NO  let y = x.get() * 2
  ✅ YES let y = move || x.get() * 2.

3. If you’re *trying* to access the value without tracking, use `.get_untracked()` or `.with_untracked()` instead.

https://github.com/tqwewe/leptos_server_signal/blob/8609c7a1165532185b69e35632785f8c2319f3ee/src/lib.rs#L141

https://github.com/tqwewe/leptos_server_signal/blob/8609c7a1165532185b69e35632785f8c2319f3ee/src/lib.rs#L127

tqwewe commented 1 year ago

Ah I see, it seems like since the closure isn't run inside an effect, I can't really use tracking here. I think everything in the callback needs to just use _untracked methods. I'll try to fix this and make a release asap.

For now, it should be safe to ignore.