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

Suspense boundaries/pure HTML out of order streaming/anyhow like error handling #2365

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

ealmloff
Copy link
Member

@ealmloff ealmloff commented Apr 24, 2024

This PR improves context based suspense by bubbling suspense to the nearest suspense boundary.

This allows you to handle suspense at a single boundary which makes it easier to show an unified loading UI.

It uses the current extension trait to return early when a suspended resource is encountered, but this now returns an error instead of None to avoid issues when the suspense is handled manually in the component.

// Suspense context
#[component]
fn Parent() -> Element {
    rsx! {
        ErrorBoundary {
            handle_error: |err| rsx! { div { {err} } },
            Suspense {
                pending: |suspense| rsx! { div { {suspense} } },
                Doggo {}
            }
        }
    }
}

#[component]
fn Doggo() -> Element {
    let download_progress = use_signal(|| 0.);
    let mut fut = use_resource(move || async move { download_model(download_progress).await })
        .suspend()
        // You can optionally add a hint for the suspense boundary to render
        .show(move || rsx!("Downloading LLM... {download_progress}% done))?
        .throw()
        // You can optionally add a hint for the error boundary to render
        .show_with(|err| rsx!("hugging face is down 🙁: {err:?}"))?;

    todo!()
}

Breaking changes:

  • This PR changes the Element type from Option to Result to make it easier to return errors early, and properly track the result of the component. Without this change, if you throw or suspend, handle it manually and then return None manually, dioxus will try to handle the suspense/error for you

Closes #1335

Stacked on top of #2226, #2437

@ealmloff ealmloff added enhancement New feature or request core relating to the core implementation of the virtualdom breaking This is a breaking change fullstack related to the fullstack crate labels Apr 24, 2024
@ealmloff ealmloff changed the title Bubble suspense and retain nodes during suspense Suspense boundaries/pure HTML out of order streaming/anyhow like error handling May 20, 2024
@ealmloff
Copy link
Member Author

Out of order SSR is working on the server. Still some work to do to make client side suspense work correctly. Out of order SSR without JS makes it possible stream updates while your WASM is still loading which should be nice for large wasm bundles

Screen.Recording.2024-05-21.at.12.15.45.PM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a breaking change core relating to the core implementation of the virtualdom enhancement New feature or request fullstack related to the fullstack crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wait for Suspense to Finish Before Removing Elements
1 participant