Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorTemplate doesn't need *two* arguments? #16

Open
srid opened this issue Aug 2, 2023 · 8 comments
Open

ErrorTemplate doesn't need *two* arguments? #16

srid opened this issue Aug 2, 2023 · 8 comments

Comments

@srid
Copy link

srid commented Aug 2, 2023

https://github.com/leptos-rs/start-axum/blob/182477f366dc0b43b909a6a845958382afcab613/src/error_template.rs#L28-L29

I can't find a reason why this requires two separate arguments. Using a single (non-optional) argument works just fine:

diff --git a/src/app.rs b/src/app.rs
index 5a5aff9..fe2814f 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -22,8 +22,9 @@ pub fn App(cx: Scope) -> impl IntoView {
         <Router fallback=|cx| {
             let mut outside_errors = Errors::default();
             outside_errors.insert_with_default_key(AppError::NotFound);
+            let errors = create_rw_signal(cx, outside_errors);
             view! { cx,
-                <ErrorTemplate outside_errors/>
+                <ErrorTemplate errors/>
             }
             .into_view(cx)
         }>
diff --git a/src/error_template.rs b/src/error_template.rs
index 3a947fa..1ad6c42 100644
--- a/src/error_template.rs
+++ b/src/error_template.rs
@@ -25,16 +25,8 @@ impl AppError {
 #[component]
 pub fn ErrorTemplate(
     cx: Scope,
-    #[prop(optional)] outside_errors: Option<Errors>,
-    #[prop(optional)] errors: Option<RwSignal<Errors>>,
+    errors: RwSignal<Errors>
 ) -> impl IntoView {
-    let errors = match outside_errors {
-        Some(e) => create_rw_signal(cx, e),
-        None => match errors {
-            Some(e) => e,
-            None => panic!("No Errors found and we expected errors!"),
-        },
-    };
     // Get Errors from Signal
     let errors = errors.get();
 
@benwis
Copy link

benwis commented Aug 2, 2023

Because if you are in Actix or Axum, and you detect an error(say 404), you can't create a Signal because you aren't in a Leptos Runtime.

@srid
Copy link
Author

srid commented Aug 2, 2023

I see. I feel like leptos error handling (at least as demoed in this template) in general needs a revamp. It has been hard for me to comprehend what this code does at first pass.

@benwis
Copy link

benwis commented Aug 2, 2023 via email

@teenjuna
Copy link

teenjuna commented Aug 5, 2023

@benwis by the way, when the standard ErrorTemplate from the template is invoked, I see this message in console:

At src/error_template.rs:39:25, you access a signal or memo (defined at src/error_template.rs:32:20) outside a reactive tracking context. This might mean your app is not responding to changes in signal values in the way you expect.

Related line:

let errors = errors.get();

@srid
Copy link
Author

srid commented Aug 20, 2023

I've managed to decouple static file handling & error/404 handling such that SSR works with ErrorBoundary. If anybody is interested, you can find the relevant code here:

https://github.com/juspay/nix-browser/blob/3717f9ed1d885e96d153b72b5779909e5667df52/src/server.rs#L68-L79

EDIT: Here's the ErrorTemplate rewrite:

https://github.com/juspay/nix-browser/blob/3717f9ed1d885e96d153b72b5779909e5667df52/src/widget.rs#L75-L90

@gbj
Copy link
Contributor

gbj commented Aug 25, 2023

@teenjuna I've fixed the untracked read warning in 68ca319

@teenjuna
Copy link

@teenjuna I've fixed the untracked read warning in 68ca319

That's great. But I'm sure I tried that and the warning was still there... Maybe I changed something else and it had an effect

@xbb
Copy link

xbb commented Sep 27, 2023

Also it panics on line 53, when there is at least an error (ServerFnError in my case) and no AppError

https://github.com/leptos-rs/start-axum/blob/68ca319700b02bd2f2e83601ee015e09155c060a/src/error_template.rs#L41-L55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants