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

Transition doesn't show fallback while pending #562

Closed
kiyov09 opened this issue Feb 21, 2023 · 7 comments
Closed

Transition doesn't show fallback while pending #562

kiyov09 opened this issue Feb 21, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@kiyov09
Copy link

kiyov09 commented Feb 21, 2023

I noticed that the Transition component is not rendering the fallback while the resource inside is still pending.

Example Code

pub async fn test_resources() -> Vec<String> {
    std::thread::sleep(std::time::Duration::from_secs(2));
    vec![
        "Fizz".to_string(),
        "Buzz".to_string(),
        "FizzBuzz".to_string(),
    ]
}

#[component]
pub fn ResourcesIssue(cx: Scope) -> impl IntoView {
    let resource = create_resource(cx, move || (), move |_| test_resources());

    view! {
        cx,
        <div>
            <Transition fallback=move || view!{ cx, <p>"Loading..."</p>}>
            {
                move || resource.read(cx).map(|strs|
                    strs.iter()
                        .map(|s| view!{ cx, <p>{s}</p>})
                        .collect::<Vec<_>>(),
                )
            }
            </Transition>
        </div>
    }
}

I was analyzing the code and seems to be related to this if-else block:

if let Some(prev_children) = &*prev_child.borrow() {
prev_children.clone().into_view(cx)
} else {
fallback().into_view(cx)
}

gbj added a commit that referenced this issue Feb 21, 2023
@gbj
Copy link
Collaborator

gbj commented Feb 21, 2023

Ah, thanks very much for reporting this!

@gbj gbj closed this as completed in 46f6ded Feb 21, 2023
@kiyov09
Copy link
Author

kiyov09 commented Feb 21, 2023

@gbj
First of all thnx for your work on this. 💪

It's working now but only when combined with create_resource. If I used create_local_resource (which I'm doing in my project) the issue is still there.

@kiyov09
Copy link
Author

kiyov09 commented Feb 21, 2023

Probably the new first_run Cell needs to be read/modified inside the fallback instead of the children
At least that works for me.

I can continue with this if you want.

@gbj
Copy link
Collaborator

gbj commented Feb 21, 2023

Probably the new first_run Cell needs to be read/modified inside the fallback instead of the children

At least that works for me.

I can continue with this if you want.

Ah okay! Want to make a PR?

@gbj gbj reopened this Feb 21, 2023
@kiyov09
Copy link
Author

kiyov09 commented Feb 22, 2023

Sure. I'll work on that tomorrow morning. Is that ok?

@kiyov09
Copy link
Author

kiyov09 commented Feb 23, 2023

@gbj
Ok, I found what's the issue, but I don't know the proper way to fix it.
When on hydrate mode, the first run happens on the server, which sends the initial HTML with the fallback on it ("Loading..." in this case). When it gets to the client, the prev_children gets updated right away in the first run but it is an "invisible" element cause the resource is still pending (See screenshot below), so the fallback element sent by the server is removed.

Screenshot 2023-02-23 at 10 13 10

@gbj gbj added the bug Something isn't working label Feb 24, 2023
@gbj
Copy link
Collaborator

gbj commented Feb 24, 2023

Ah okay I'll take a look.

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