Provide custom state in file_and_error_handler
#3408
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 usesexpect_context
).The handler 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 theadditional_context
parameter ofhandle_response_inner
.I think this might technically be a semver breaking change because we're adding constraints to the
S
type parameter. However, I think it should be fine because any custom state used with this method would need to satisfy these constraints to be used in the first place (e.g., in the LeptosRoutes trait). However, I'll leave it up to you to decide if a version bump is needed, or if there's a way to do this without requiring changing the type constraints.