DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.45k stars 747 forks source link

Compilation error when child component in different module #2053

Closed jonnyandrew closed 4 months ago

jonnyandrew commented 4 months ago

Problem

A component with props including a Signal cannot be put in a different module to the parent component.

Steps To Reproduce

Minimal sample:

use dioxus::prelude::*;
fn RootComponent() -> Element {
    let number = use_signal(|| 42);
    rsx! {
        components::MyComponent {
            number: number,
        }
    }
}

mod components {
    use dioxus::prelude::*;
    #[component]
    pub(super) fn MyComponent(number: ReadOnlySignal<u64>) -> Element {
        rsx! {
            div { "{number}" }
        }
    }
}

The error I'm seeing:

error[E0631]: type mismatch in function arguments
  --> ui/src/lib.rs:44:9
   |
43 | /     rsx! {
44 | |         components::MyComponent {
   | |         ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
45 | |             number: number,
46 | |         }
47 | |     }
   | |_____- required by a bound introduced by this call
...
53 |       #[component]
   |       ------------ found signature defined here
   |
   = note: expected function signature `fn(MyComponentPropsWithOwner) -> _`
              found function signature `fn(MyComponentProps) -> _`
   = note: required for `fn(MyComponentProps) -> Option<VNode> {MyComponent}` to implement `dioxus::prelude::ComponentFunction<MyComponentPropsWithOwner>`

Expected behavior

The above sample compiles like it does when the two components are in the same module.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

Questionnaire