feat: display error overlay (#607)

Co-authored-by: Marco Pasqualetti <marco.pasqualetti@live.com>
This commit is contained in:
Valerio Ageno
2025-03-09 11:32:05 +01:00
committed by GitHub
parent da194524ee
commit 77c902a7a5
7 changed files with 412 additions and 15 deletions
+21 -10
View File
@@ -36,10 +36,10 @@ struct ProdJs;
impl ProdJs {
thread_local! {
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
Ssr::from(
read_to_string(PathBuf::from(PROD_BUNDLE_PATH)).expect("Server bundle not found"), ""
).unwrap()
)
Ssr::from(
read_to_string(PathBuf::from(PROD_BUNDLE_PATH)).expect("Server bundle not found"), ""
).unwrap()
)
}
}
@@ -47,11 +47,22 @@ struct DevJs;
impl DevJs {
pub fn render_to_string(params: Option<&str>) -> Result<String, SsrError> {
Ssr::from(
read_to_string(PathBuf::from(DEV_BUNDLE_PATH)).expect("Server bundle not found"),
"",
)
.unwrap()
.render_to_string(params)
let bundle_path = read_to_string(PathBuf::from(DEV_BUNDLE_PATH));
if let Ok(source) = bundle_path {
let ssr = Ssr::from(source, "");
if let Ok(mut ssr) = ssr {
ssr.render_to_string(params)
} else {
let fallback_html = read_to_string(PathBuf::from("./.tuono/index.html"))
.unwrap_or("Fallback HTML not loaded".to_string());
Ok(fallback_html.replace("[SERVER_PAYLOAD]", params.unwrap_or("")))
}
} else {
let fallback_html = read_to_string(PathBuf::from("./.tuono/index.html"))
.unwrap_or("Fallback HTML not loaded".to_string());
Ok(fallback_html.replace("[SERVER_PAYLOAD]", params.unwrap_or("")))
}
}
}