Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullstack app on 0.6 with context fails to share the state on server functions #3064

Closed
fabiodcorreia opened this issue Oct 16, 2024 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@fabiodcorreia
Copy link

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

@david-boles
Copy link

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?

@david-boles
Copy link

Although, actually, in this case, it might be due to providing a browser::BrowserManager but attempting to extract an Arc<browser::BrowserManager>?

@jkelleyrtp jkelleyrtp added the bug Something isn't working label Jan 7, 2025
@jkelleyrtp jkelleyrtp added this to the 0.6.2 milestone Jan 9, 2025
@ealmloff
Copy link
Member

It looks like this issue has been fixed in the git version of dioxus after #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(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants