From e9d05b1d24fd9f43364252c87fa70c03158fdbd6 Mon Sep 17 00:00:00 2001 From: Spencer Ferris <3319370+spencewenski@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:55:09 -0800 Subject: [PATCH] Provide custom state in `file_and_error_handler` The `file_and_error_handler` provided by leptos_axum does not provide the app's custom state in the context. This means that when the fallback handler tries to render the app, the app will not be able to access the custom state (and will panic if it uses `expect_context`). The handle defined by `file_and_error_handler` has access to the custom state from Axum, so we can pass the custom state from Axum into the Leptos handler using the `additional_context` parameter of `handle_response_inner`. --- integrations/axum/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 9c4ac0b22d..a3b824e42d 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -1994,12 +1994,12 @@ pub fn file_and_error_handler( + 'static where IV: IntoView + 'static, - S: Send + 'static, + S: Send + Sync + Clone + 'static, LeptosOptions: FromRef, { - move |uri: Uri, State(options): State, req: Request| { + move |uri: Uri, State(state): State, req: Request| { Box::pin(async move { - let options = LeptosOptions::from_ref(&options); + let options = LeptosOptions::from_ref(&state); let res = get_static_file(uri, &options.site_root, req.headers()); let res = res.await.unwrap(); @@ -2007,7 +2007,9 @@ where res.into_response() } else { let mut res = handle_response_inner( - || {}, + move || { + provide_context(state.clone()); + }, move || shell(options), req, |app, chunks| {