Skip to content

Confused on how to trigger signal/resource use warnings #4026

Closed
@lukexor

Description

@lukexor

Describe the bug

I've seen the warnings emitted by leptos when using signals outside of a reactive context, or resources outside of suspense, but I haven't seen them in my own project and confused as to why.

I was able to set up a scenario where they should be triggered but I still don't see them.

Leptos Dependencies

v0.8.2 leptos todo_app_sqlite_axum example

To Reproduce

  • Add the following items to the example (pulled from a closed issue on the same topic)
async fn load_data(count: ReadSignal<i32>, set_count: WriteSignal<i32>) {
    let new_data = move || count.get() + 1;
    set_count.set(new_data());
}

#[component]
pub fn BlockNumber() -> impl IntoView {
    let (count, set_count) = signal(0); // Warning line number

    let action = Action::new(
        |&(count, set_count): &(ReadSignal<i32>, WriteSignal<i32>)| async move {
            load_data(count, set_count).await
        },
    );

    view! {
        <p>{move || count.get()}</p>
        <button on:click=move |_| {
            action.dispatch((count, set_count));
        }>Click</button>
    }
}
  • And add <BlockNumber /> to one of the views.
  • Run cargo leptos watch
  • Click the button

A warning should be logged about reading a signal non-reactively

I also tried an even simpler version with no warnings either:

#[component]
pub fn Counter() -> impl IntoView {
    let (count, set_count) = signal(0);

    view! {
        <p>{count.get()}</p>
        <button on:click=move |_| {
            set_count.set(count.get() + 1);
        }>Click</button>
    }
}

I haven't been able to see warnings for using Resource outside of suspense either.

Is there something I'm missing? I see in the source that it relies on debug_assertions and effects, as well as being outside of a SpecialNonReactiveZone and as far as I can tell all those conditions should be true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions