Bubble errors from the server to the client on suspense boundaries (#2772)
* Bubble errors from the server to the client on suspense boundaries * make resolving suspense boundaries O(n)
This commit is contained in:
1 parent
3003362b52
commit
b0a2e2418c
12 files changed
+190
-39
No files matched your search
@@ -40,13 +40,11 @@ impl Display for CapturedPanic {
|
||||
impl Error for CapturedPanic {}
|
||||
|
||||
/// Provide an error boundary to catch errors from child components
|
||||
pub fn use_error_boundary() -> ErrorContext {
|
||||
use_hook(|| {
|
||||
provide_context(ErrorContext::new(
|
||||
Vec::new(),
|
||||
current_scope_id().unwrap_or_else(|e| panic!("{}", e)),
|
||||
))
|
||||
})
|
||||
pub fn provide_error_boundary() -> ErrorContext {
|
||||
provide_context(ErrorContext::new(
|
||||
Vec::new(),
|
||||
current_scope_id().unwrap_or_else(|e| panic!("{}", e)),
|
||||
))
|
||||
}
|
||||
|
||||
/// A trait for any type that can be downcast to a concrete type and implements Debug. This is automatically implemented for all types that implement Any + Debug.
|
||||
@@ -750,7 +748,7 @@ impl<
|
||||
/// Error boundaries are quick to implement, but it can be useful to individually handle errors in your components to provide a better user experience when you know that an error is likely to occur.
|
||||
#[allow(non_upper_case_globals, non_snake_case)]
|
||||
pub fn ErrorBoundary(props: ErrorBoundaryProps) -> Element {
|
||||
let error_boundary = use_error_boundary();
|
||||
let error_boundary = use_hook(provide_error_boundary);
|
||||
let errors = error_boundary.errors();
|
||||
if errors.is_empty() {
|
||||
std::result::Result::Ok({
|
||||
@@ -768,6 +766,8 @@ pub fn ErrorBoundary(props: ErrorBoundaryProps) -> Element {
|
||||
)
|
||||
})
|
||||
} else {
|
||||
tracing::trace!("scope id: {:?}", current_scope_id());
|
||||
tracing::trace!("handling errors: {:?}", errors);
|
||||
(props.handle_error.0)(error_boundary.clone())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user