DioxusLabs / DioxusLabs/dioxus
RSX macro changes expression evaluation order
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
The rsx macro can include expressions in the dynamic nodes or dynamic attributes arrays. We evaluate all expressions in the dynamic nodes before expressions in the dynamic attributes. This can lead to counterintuitive compiler errors because the execution order is changed
**Steps To Reproduce**
This code looks like it would work in debug and release mode, but it fails to compile in release mode:
```rust
use dioxus::prelude::*;
#[derive(Clone, PartialEq, Eq)]
struct TestOuter;
impl TestOuter {
fn borrow(&self) -> String {
"".to_string()
}
}
fn Parent() -> Element {
let outer = TestOuter;
rsx! {
Fragment { key: outer.borrow(),
Child { outer }
}
}
}
#[component]
fn Child(outer: TestOuter) -> Element {
rsx! {
div { "Hello" }
}
}
fn main() {}
```
**Expected behavior**
The RSX macro should execute expressions in the order they were created in. We could pull out all expressions in the rsx macro and evaluate them in order then use the results as needed inside the macro expansion.
**Environment:**
- Dioxus version: main
- Rust version: nightly
- OS info: macO
- App platform: all
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.