Fullstack app on 0.6 with context fails to share the state on server functions
Problem
Shared context on server server functions doesn't work on alpha.3 but was working fine on alpha.2. On 3 when I try to grab the state from the context I get ServerError|"alloc::sync::Arc<browser::BrowserManager>" not found in server context.
I also tried with other types like an empty struct Pool as described on the examples but the result is the same.
Steps To Reproduce
Steps to reproduce the behavior:
Create a fullstack app with context and without router.
LaunchBuilder::new()
.with_context(server_only! {browser::BrowserManager::new()}) //The method new returns an Arc
.launch(App);
On the server function try to grab the object manager
let FromContext(manager): FromContext<Arc<browser::BrowserManager>> = extract().await?;
When the server function is invoked from the frontend the error above described happens.
Expected behavior
Expected the state to be accessible on the server function.
Screenshots
Environment:
- Dioxus version: v0.6.0-alpha.3
- Rust version: 1.81
- OS info: MacOS Intel
- App platform: Fullstack
Questionnaire
I'm interested in fixing this myself but don't know where to start
I'm running into this too, in my case launching via .serve_dioxus_application(ServeConfig::builder().context_providers(...)....
@fabiodcorreia any chance you found a workaround?
Although, actually, in this case, it might be due to providing a browser::BrowserManager but attempting to extract an Arc<browser::BrowserManager>?
It looks like this issue has been fixed in the git version of dioxus after https://github.com/DioxusLabs/dioxus/pull/3552. This code works with the git version of dioxus and the CLI. We also have a playwright test for this behavior now:
// [dependencies]
// dioxus = { git = "https://github.com/DioxusLabs/dioxus", features = ["fullstack"] }
// [features]
// web = ["dioxus/web"]
// server = ["dioxus/server"]
#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
dioxus::LaunchBuilder::new()
.with_context(1234u32)
.launch(app);
}
fn app() -> Element {
use_server_future(server_function)?;
rsx! {
"hello"
}
}
#[server]
async fn server_function() -> Result<(), ServerFnError> {
let FromContext(data): FromContext<u32> = extract().await.unwrap();
assert_eq!(data, 1234u32);
println!("Server received: {}", data);
Ok(())
}