Skip to content

Effects aren't run inside the error handler when an error is thrown from the server through a suspense boundary #4635

@ealmloff

Description

@ealmloff

Problem

Effects aren't run on the client if the server throws an error through a suspense boundary

Steps To Reproduce

Steps to reproduce the behavior:

Run this reproduction from this thread in discord:

use dioxus::prelude::*;

fn main() {
    dioxus::launch(app);
}

#[server]
pub async fn delayed_error() -> Result<(), ServerFnError> {
    // It works without this delay, but breaks with the delay
    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    Err(ServerFnError::new("dot dot dot"))
}

#[component]
fn SimpleEffect() -> Element {
    use_effect(move || panic!("boo"));
    rsx! {
        {"Simple effect rsx"}
    }
}

#[component]
fn app() -> Element {
    rsx! {
        ErrorComp {
            SuspenseBoundary {
                fallback: |_context: SuspenseContext| rsx! {
                    div { "Loading..." }
                },
                ErrorPage {}
            }
        }
    }
}

#[component]
fn ErrorPage() -> Element {
    use_server_future(|| async move { delayed_error().await })?
        .read()
        .as_ref()
        .cloned()
        .unwrap()?;
    rsx! {}
}

#[component]
fn ErrorComp(children: Element) -> Element {
    rsx! {
        ErrorBoundary {
            handle_error: |_| {
                rsx! {
                    {"Hello from error comp"}
                    SimpleEffect {}
                }
            },
            {children}
        }
    }
}

Expected behavior

The effect should run

Environment:

  • Dioxus version: main
  • Rust version: nightly
  • OS info: macOS
  • App platform: web

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfullstackrelated to the fullstack crate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions