Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple query_signals cancel out each other's writes #2369

Open
purung opened this issue Feb 26, 2024 · 0 comments
Open

Multiple query_signals cancel out each other's writes #2369

purung opened this issue Feb 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@purung
Copy link

purung commented Feb 26, 2024

Describe the bug
When updating more than one query_signal in the same closure, only the last write has an effect.

Leptos Dependencies

leptos = { version = "0.6", features = ["csr", "nightly"] }
leptos_meta = { version = "0.6", features = ["csr", "nightly"] }
leptos_router = { version = "0.6", features = ["csr", "nightly"] }

To Reproduce
Steps to reproduce the behavior:

  1. Create two query_signals
  2. Trigger a closure that updates both signals
  3. Notice that only the last write has had an effect on the url

Expected behavior
Writes to each query_signal has an immediate effect.

Additional context
Additionally, it is clear that writes to a query_signal do not take effect until after the closure has run.

Minimal example

#[component]
pub fn TestQuery() -> impl IntoView {
    let (r_from, w_from) = create_query_signal::<String>("from");
    let (r_to, w_to) = create_query_signal::<String>("to");
    let switch = move |_| {
        log!("Before from: {:?}", r_from());
        log!("Before to: {:?}", r_to());
        w_from(r_to());
        w_to(None);
        log!("After from: {:?}", r_from());
        log!("After to: {:?}", r_to());
    };
    view! {
        <div class="flex flex-col gap-4 p-8">
            <div>Current from: {r_from}</div>
            <div>Current to: {r_to}</div>
            <button type="button" on:click=switch class="btn">
                Switch
            </button>
        </div>
    }
}

Output after first click:

Before from: Some("Original from")
Before to: Some("Original to")
After from: Some("Original from")
After to: Some("Original to")

Output after second click:

Before from: Some("Original from")
Before to: None
After from: Some("Original from")
After to: None

This should support the idea that 1) The last write "wins" and 2) Writes do not take immediate effect.

@gbj gbj added the bug Something isn't working label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants