Fix clearing error boundaries (#4041)
This commit is contained in:
1 parent
28a85ab614
commit
04b14c5abc
2 files changed
+129
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::{prelude::*, CapturedError};
|
||||
|
||||
#[test]
|
||||
fn catches_panic() {
|
||||
@@ -30,3 +30,50 @@ fn ThrowChild() -> Element {
|
||||
|
||||
rsx! { div {} }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_error_boundary() {
|
||||
static THREW_ERROR: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
rsx! {
|
||||
AutoClearError {}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ThrowsError() -> Element {
|
||||
if THREW_ERROR.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
THREW_ERROR.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
Err(CapturedError::from_display("This is an error").into())
|
||||
} else {
|
||||
rsx! {
|
||||
"We should see this"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn AutoClearError() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundary {
|
||||
handle_error: |error: ErrorContext| {
|
||||
error.clear_errors();
|
||||
|
||||
rsx! {
|
||||
"We cleared it"
|
||||
}
|
||||
},
|
||||
|
||||
ThrowsError {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
||||
let out = dioxus_ssr::render(&dom);
|
||||
|
||||
assert_eq!(out, "We should see this");
|
||||
}
|
||||
Reference in new issue
Block a user