Skip to content

RSX macro changes expression evaluation order #3737

Open
@ealmloff

Description

@ealmloff

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:

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingrsxRelated to rsx or the dioxus-rsx crate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions