DioxusLabs / DioxusLabs/dioxus

Restrict calling signals as functions for only `Copy` values instead of `Clone`

Open
#4,412 4 comments 2 reactions 0 assignees View on GitHub
breaking signals
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

There is a footgun with signals that i say **way too many** people falling into, like, way too many.

You can currently call signals not just for types that implement `Copy`, but also for those that implement `Clone`

For example, here is a terrible code:

```rs
let list = use_signal(|| vec![1, 2, 3, 4, ...]);

rsx!(
for i in 0..5 {
p { key: "{i}", "{list()[i]}" }
}
)
```

For every `list()` the entire vec gets cloned. Which is obviously completely unnecessary and terrible.

Here is a not-so-terrible code:

```rs
let list = use_signal(|| vec![1, 2, 3, 4, ...]);

rsx!(
for i in 0..5 {
p { key: "{i}", "{list.read()[i]}" }
}
)
```

So, I suggest restricting calling signals for only types that implement `Copy`, just like what [this comment](https://github.com/DioxusLabs/dioxus/blob/97947b169b48ebc30957ce7e3e1ca9c32ec65389/packages/signals/src/signal.rs#L487) says, instead of everything that implements `Clone`.

I know this is a breaking, but it is necessary imo.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.