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

Static site generation race condition #3518

Closed
ealmloff opened this issue Jan 8, 2025 · 0 comments · Fixed by #3521
Closed

Static site generation race condition #3518

ealmloff opened this issue Jan 8, 2025 · 0 comments · Fixed by #3521
Assignees
Labels
bug Something isn't working cli Related to the dioxus-cli program static-generation

Comments

@ealmloff
Copy link
Member

ealmloff commented Jan 8, 2025

Problem

Running static generation is a race condition between a 10 second timer and the site actually rendering. This caused the docsite build to silently fail and deploy the broken site

Steps To Reproduce

Steps to reproduce the behavior:

  • Create a new project with this code:
// [dependencies]
// dioxus = { version = "0.6.0", features = ["fullstack", "router"] }
// tokio = { version = "1.42.0", features = ["full"], optional = true }
// tracing = "0.1.41"

// [features]
// default = []
// web = ["dioxus/web"]
// server = ["dioxus/server", "dep:tokio"]

use dioxus::prelude::*;

fn main() {
    LaunchBuilder::new()
        .with_cfg(server_only! {
            ServeConfig::builder().incremental(
                    IncrementalRendererConfig::new()
                        .static_dir(std::path::PathBuf::from("./docs"))
                        .clear_cache(false)
                )
            .build()
            .expect("Unable to build ServeConfig")
        })
        .launch(|| {
            rsx! {
                Router<Route> {}
            }
        })
}

#[derive(Routable, Clone, PartialEq, Eq, Hash)]
enum Route {
    #[route("/")]
    Home,
    #[route("/other_route")]
    OtherRoute,
}

fn Home() -> Element {
    use_server_future(pause)?;

    rsx! {
        div {
            h1 {"Hello, world!"}
        }
    }
}

fn OtherRoute() -> Element {
    rsx! {
        div {
            h1 {"Hello, world!"}
        }
    }
}

#[server]
async fn pause() -> Result<(), ServerFnError> {
    tokio::time::sleep(std::time::Duration::from_secs(60)).await;
    Ok(())
}

#[server(endpoint = "static_routes")]
async fn static_routes() -> Result<Vec<String>, ServerFnError> {
    Ok(Route::static_routes()
        .into_iter()
        .map(|route| route.to_string())
        .collect::<Vec<_>>())
}
  • Run dx build --ssg
  • Observe the generated site has no content

Expected behavior

SSG should not silently fail to build when it takes more than 10 seconds

Environment:

  • Dioxus version: 0.6
  • Rust version: nightly
  • OS info: MacOS
  • App platform: ssg
@ealmloff ealmloff added bug Something isn't working cli Related to the dioxus-cli program static-generation labels Jan 8, 2025
@ealmloff ealmloff self-assigned this Jan 8, 2025
@ealmloff ealmloff mentioned this issue Jan 8, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the dioxus-cli program static-generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant