error_boundary.rs 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use dioxus::prelude::*;
  2. use futures_util::Future;
  3. #[test]
  4. fn catches_panic() {
  5. let mut dom = VirtualDom::new(app);
  6. let a = dom.rebuild();
  7. dbg!(a);
  8. }
  9. fn app(cx: Scope) -> Element {
  10. cx.render(rsx! {
  11. div {
  12. h1 { "Title" }
  13. NoneChild {}
  14. }
  15. })
  16. }
  17. fn NoneChild(cx: Scope) -> Element {
  18. None
  19. }
  20. fn PanicChild(cx: Scope) -> Element {
  21. panic!("Rendering panicked for whatever reason");
  22. cx.render(rsx! {
  23. h1 { "It works!" }
  24. })
  25. }
  26. fn ThrowChild(cx: Scope) -> Element {
  27. cx.throw(std::io::Error::new(std::io::ErrorKind::AddrInUse, "asd"))?;
  28. let g: i32 = "123123".parse().throw(cx)?;
  29. cx.render(rsx! {
  30. div {}
  31. })
  32. }
  33. fn custom_allocator(cx: Scope) -> Element {
  34. let g = String::new();
  35. let p = g.as_str();
  36. let g2 = cx.use_hook(|| 123);
  37. // cx.spawn(async move {
  38. // //
  39. // // println!("Thig is {p}");
  40. // });
  41. None
  42. }