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

create_local_resource does not refetch when source signal changes on experimental-islands #2237

Closed
Houski opened this issue Jan 27, 2024 · 3 comments

Comments

@Houski
Copy link
Contributor

Houski commented Jan 27, 2024

Describe the bug
A create_local_resource inside an island does not re-run the fetcher when the source signal changes, in Leptos 6.0 beta versions (so far).

It was previously working on Leptos 5.5 (3f34d9b)

In this reproduction, you can see that the signal when routed through the LocalResourceTest ServerFn, does not re-run and match the signal itself. It remains blank, as it only appears to run the fetcher on initial load.

To Reproduce

use leptos::*;

#[server(LocalResourceTest, "/api")]
pub async fn local_resource_test(input: String) -> Result<String, ServerFnError> {
    Ok(input)
}

#[component]
pub fn Test() -> impl IntoView {
    view! { <TestIsland/> }
}

#[island]
pub fn TestIsland() -> impl IntoView {
    let (input, set_input) = create_signal("".to_string());

    let local_resource_test = create_local_resource(move || input(), move |input| local_resource_test(input));

    view! {
        <input style="border: 1px solid black;" type="text" on:input=move |ev| { set_input(event_target_value(&ev)) }/>

        <div>
            <Transition fallback=move || ()>

                {move || match local_resource_test.get() {
                    Some(Ok(result)) => format!("Here is the response from the local resource: {}", result),
                    _ => "".to_string(),
                }}

            </Transition>
        </div>

        {move || format!("Here is the input signal, so you can see it does update and change and should trigger the re-fetch: {}", input())}
    }
}
@gbj
Copy link
Collaborator

gbj commented Jan 28, 2024

I’m on my phone because my computer is being used to watch Moana for the 100th time, but if you want to try a local patch or make a PR: leptos_reactive/src/resource.rs needs a source.track() inserted at line 388, just before r.load(). When I fixed #2221 I missed adding the tracking back here in addition to the other helper for resources.

@benwis
Copy link
Contributor

benwis commented Jan 28, 2024

Can you retry against git main @Houski , I merged Greg's commit and am hoping it works for you

@Houski
Copy link
Contributor Author

Houski commented Jan 28, 2024

Confirmed, latest version at this moment fixes the issue.

@Houski Houski closed this as completed Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants