Files
dioxus/packages/playwright-tests/fullstack-errors/src/main.rs
T
Jonathan Kelley f2b1c6d97f codify "platform" into resolution logic, server-fn/fullstack overhaul (#4596)
overhaul dioxus fullstack using a new implementation of server_fn

This PR is a complete rewrite of dioxus fullstack designed to improve compatibility with axum and to fix a number of compilation errors based on feature flag unification plumbing through macros.
2025-10-03 18:26:19 -07:00

68 lines
1.7 KiB
Rust

// This test is used by playwright configured in the root of the repo
// Tests:
// - Errors that originate in the initial render
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
rsx! {
Errors {}
}
}
#[server]
async fn server_error() -> ServerFnResult<String> {
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
Err(ServerFnError::new("the server threw an error!"))
}
#[component]
fn Errors() -> Element {
rsx! {
// This is a tricky case for suspense https://github.com/DioxusLabs/dioxus/issues/2570
// Root suspense boundary is already resolved when the inner suspense boundary throws an error.
// We need to throw the error from the inner suspense boundary on the server to the hydrated
// suspense boundary on the client
ErrorBoundary {
handle_error: |_| rsx! {
ErrorFallbackButton {}
},
SuspenseBoundary {
fallback: |_: SuspenseContext| rsx! {
div {
"Loading..."
}
},
ThrowsError {}
}
}
}
}
#[component]
pub fn ErrorFallbackButton() -> Element {
let mut count = use_signal(|| 0);
rsx! {
// Make sure the error fallback is interactive after hydration
button {
id: "error-fallback-button",
onclick: move |_| count += 1,
"Error fallback button clicked {count} times"
}
}
}
#[component]
pub fn ThrowsError() -> Element {
use_server_future(server_error)?.unwrap()?;
rsx! {
"success"
}
}