Compare commits

..

2 Commits

Author SHA1 Message Date
Greg Johnston
0588c89bba Add html-escape dependency for view macro 2023-01-31 23:56:32 -05:00
Greg Johnston
169e55660c Make all fragment rendering lazy (closes #299 and #421) 2023-01-31 23:36:33 -05:00
4 changed files with 12 additions and 7 deletions

View File

@@ -16,7 +16,10 @@ pub fn ErrorTemplate(
#[prop(optional)] errors: Option<RwSignal<Errors>>,
) -> impl IntoView {
let errors = match outside_errors {
Some(e) => create_rw_signal(cx, e),
Some(e) => {
let errors = create_rw_signal(cx, e);
errors
}
None => match errors {
Some(e) => e,
None => panic!("No Errors found and we expected errors!"),
@@ -29,7 +32,8 @@ pub fn ErrorTemplate(
// Downcast lets us take a type that implements `std::error::Error`
let errors: Vec<AppError> = errors
.into_iter()
.filter_map(|(_k, v)| v.downcast_ref::<AppError>().cloned())
.map(|(_k, v)| v.downcast_ref::<AppError>().cloned())
.flatten()
.collect();
println!("Errors: {errors:#?}");
@@ -50,7 +54,7 @@ pub fn ErrorTemplate(
// a function that returns the items we're iterating over; a signal is fine
each= move || {errors.clone().into_iter().enumerate()}
// a unique key for each item as a reference
key=|(index, _error)| *index
key=|(index, _error)| index.clone()
// renders each item to a view
view= move |error| {
let error_string = error.1.to_string();

View File

@@ -33,13 +33,14 @@ if #[cfg(feature = "ssr")] {
async fn get_static_file(uri: Uri, root: &str) -> Result<Response<BoxBody>, (StatusCode, String)> {
let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap();
let root_path = format!("{root}");
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
// This path is relative to the cargo root
match ServeDir::new(root).oneshot(req).await {
match ServeDir::new(&root_path).oneshot(req).await {
Ok(res) => Ok(res.map(boxed)),
Err(err) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {err}"),
format!("Something went wrong: {}", err),
)),
}
}

View File

@@ -64,7 +64,7 @@ pub fn ExampleErrors(cx: Scope) -> impl IntoView {
<a href="/404">"This Page Does not Exist"</a>
</p>
<p>
"The following <div> will always contain an error and cause the page to produce status 500. Check browser dev tools. "
"The following &ltdiv&gt will always contain an error and cause the page to produce status 500. Check browser dev tools. "
</p>
<div>
<ErrorBoundary fallback=|cx, errors| view!{cx, <ErrorTemplate errors=errors/>}>

View File

@@ -37,7 +37,7 @@ if #[cfg(feature = "ssr")] {
// Setting this to None means we'll be using cargo-leptos and its env vars
let conf = get_configuration(None).await.unwrap();
let leptos_options = conf.leptos_options;
let addr = leptos_options.site_address;
let addr = leptos_options.site_address.clone();
let routes = generate_route_list(|cx| view! { cx, <App/> }).await;
// build our application with a route