dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

fullstack: 0.7.0-rc.2 breaks custom axum setups (missing .js/.wasm entry point)

Open fasterthanlime opened this issue 1 year ago • 10 comments

Problem

dx serve --web runs the server, server-side rendering works, but the HTML served doesn't have any scripts that load the .wasm

The .wasm and the glue .js are present in the target folder.

Steps To Reproduce

Steps to reproduce the behavior:

  • Upgrade a fullstack app from rc.1 to rc.2
  • That's it?

Expected behavior

Ideally, code should run client-side x)

Screenshots

No wasm/js (rc.2):

Image

wasm/js (rc.1):

Image

Environment:

  • Dioxus version: rc.2
  • Rust version: 1.90
  • OS info: macOS 26
  • App platform: web

fasterthanlime avatar Oct 16 '25 15:10 fasterthanlime

Can reproduce this both on macOS as well as Windows 11. Was already wondering why the page loads, but no interaction is possible. Thanks for investigating.

critx-jeti avatar Oct 16 '25 16:10 critx-jeti

Hmmmm I can't seem to reproduce this on a fresh project. I don't think we changed anything major that could've broken this.

Can you guys try removing target/dx and then running the command again? Could be something related to CLI version upgrade + hashes.

jkelleyrtp avatar Oct 16 '25 20:10 jkelleyrtp

Can you guys try removing target/dx and then running the command again? Could be something related to CLI version upgrade + hashes.

I nuked target several times while debugging this, no dice.

fasterthanlime avatar Oct 16 '25 20:10 fasterthanlime

Did you update the CLI as well? I don't think anything should've changed there but is still good to verify

cargo binstall dioxus-cli -y --force --version 0.7.0-rc.2

Also, can you check if there's an index.html in your public folder? We use that file to bootstrap the SSR system, and if it doesn't exist, we fallback to a plain index.html which won't have the JS bootstrap code. I'm not sure why we wouldn't be generating that file (nothing changed there) but that would cause this behavior.

jkelleyrtp avatar Oct 16 '25 20:10 jkelleyrtp

I definitely updated the CLI as well when testing.

My project doesn’t have a public/ folder at all?

fasterthanlime avatar Oct 16 '25 20:10 fasterthanlime

Here's the output of 0.7.0-rc.2's dx serve --web with verbose logging on macOS:

22:41:14 [dev] Verbose logging is now on 
22:41:14 [dev] Build completed successfully in 719068us: "/Users/<user>/RustroverProjects/<project>/target/aarch64-apple-darwin/server-dev/ccrs" 
22:41:14 [dev] Bundle created at /Users/<user>/RustroverProjects/<project>/target/dx/ccrs/debug/web 
22:41:14 [dev] Build completed in 729ms 
22:41:15 [dev] Found asset at offset 2559368: "/Users/<user>/RustroverProjects/<project>/assets/favicon.ico" 
22:41:15 [dev] Found asset at offset 2559912: "/Users/<user>/RustroverProjects/<project>/assets/tailwind.css" 
22:41:15 [dev] Found asset at offset 2560456: "/Users/<user>/RustroverProjects/<project>/assets/main.css" 
22:41:15 [dev] Writing asset to offset 2559368: BundledAsset { absolute_source_path: "/Users/<user>/RustroverProjects/<project>/assets/favicon.ico", bundled_path: "favicon-dxh33c1db72d930e7ca.ico", options: AssetOptions { add_hash: true, variant: Unknown } } 
22:41:15 [dev] Writing asset to offset 2559912: BundledAsset { absolute_source_path: "/Users/<user>/RustroverProjects/<project>/assets/tailwind.css", bundled_path: "tailwind-dxh904b817ed364a81e.css", options: AssetOptions { add_hash: true, variant: Unknown } } 
22:41:15 [dev] Writing asset to offset 2560456: BundledAsset { absolute_source_path: "/Users/<user>/RustroverProjects/<project>/assets/main.css", bundled_path: "main-dxhbabb811e4aebb38.css", options: AssetOptions { add_hash: true, variant: Unknown } } 
22:41:15 [dev] Build completed successfully in 583885us: "/Users/<user>/RustroverProjects/<project>/target/wasm32-unknown-unknown/wasm-dev/ccrs.wasm" 
22:41:15 [dev] Running wasm-bindgen 
22:41:15 [dev] wasm-bindgen: [
    "--target",
    "web",
    "--debug",
    "--no-demangle",
    "--keep-debug",
    "--remove-name-section",
    "--remove-producers-section",
    "--keep-lld-exports",
    "--out-name",
    "ccrs",
    "--no-typescript",
    "--out-dir",
    "/Users/<user>/RustroverProjects/<project>/target/dx/ccrs/debug/web/public/wasm",
    "/Users/<user>/RustroverProjects/<project>/target/wasm32-unknown-unknown/wasm-dev/ccrs.wasm",
] 
22:41:17 [dev] wasm-bindgen complete in 2.443382583s 
22:41:17 [dev] Copying asset "assets/favicon.ico" to "assets/favicon.ico" 
22:41:17 [dev] Copying asset "assets/tailwind.css" to "assets/tailwind.css" 
22:41:17 [dev] Copying asset "assets/main.css" to "assets/main.css" 
22:41:17 [dev] Bundle created at /Users/<user>/RustroverProjects/<project>/target/dx/ccrs/debug/web/public 
22:41:17 [dev] Build completed in 3037ms 
22:41:17 [dev] Build completed successfully in 583ms, launching app! 💫 
22:41:17 [dev] Opening server build 
22:41:17 [dev] Opening app with main exe: "/Users/<user>/RustroverProjects/<project>/target/dx/ccrs/debug/web/ccrs-7e4cc96c" 
22:41:18 [server]  INFO Registering server function: GET /api/challenge/{pow}
22:41:18 [server]  INFO Registering server function: GET /api/challenge
22:41:35 [server] [200] / 

I've generated a generated wasm both in wasm32-unknown-unknown/wasm-dev as well as a wasm and js file in dx/app/debug/web/public/wasm. There also appears to be a correctly generated index.html file in the public folder. The generated HTML served at / does look erronous, though, especially with regard to the script tag contents and missing JS:

<title>APP</title><!DOCTYPE html>
        <html>
            <head> <link rel="stylesheet" href="/assets/tailwind-dxh904b817ed364a81e.css" type="text/css"/><link rel="stylesheet" href="/assets/main-dxhbabb811e4aebb38.css" type="text/css"/><link rel="icon" href="/assets/favicon-dxh33c1db72d930e7ca.ico"/></head>
            <body>
                <div id="main"><script>window.hydrate_queue=[];window.dx_hydrate=(id,data,debug_types,debug_locations)=>{let decoded=atob(data),bytes=Uint8Array.from(decoded,(c)=>c.charCodeAt(0));if(window.hydration_callback)window.hydration_callback(id,bytes,debug_types,debug_locations);else window.hydrate_queue.push([id,bytes,debug_types,debug_locations])};
</script><!--placeholder0--><!--placeholder1--><!--placeholder2--><!--placeholder3--><div class="min-h-screen flex flex-col" data-node-hydration="4"><!--placeholder5--><main class="grow"><div class="hero min-h-[1440px]" data-node-hydration="6"><div class="hero-content text-center align-center"><div class="max-w-md"><h1 class="text-5xl font-bold text-primary mb-16" data-node-hydration="7">Header</h1><button class="btn btn-soft btn-primary btn-wide btn-xl mt-8" data-node-hydration="8,click:1">button</button></div></div></div></main><!--placeholder10--></div><script>window.initial_dioxus_hydration_data="hoEY9oIYYRgv9oEY9YEY9YEY9Q==";window.initial_dioxus_hydration_debug_types=["core::option::Option<dioxus_core::render_error::CapturedError>","unknown","alloc::string::String","unknown","unknown","unknown","bool","unknown","bool","unknown","bool"];window.initial_dioxus_hydration_debug_locations=["/Users/<user>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-server-0.7.0-rc.2/src/ssr.rs:555:29","unknown","/Users/<user>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-fullstack-core-0.7.0-rc.2/src/history.rs:44:30","unknown","unknown","unknown","/Users/<user>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-server-0.7.0-rc.2/src/document.rs:163:14","unknown","/Users/<user>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-server-0.7.0-rc.2/src/document.rs:163:14","unknown","/Users/<user>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-server-0.7.0-rc.2/src/document.rs:163:14"];</script></div>
            </body>
        </html>

The error types appear to correspond to return values of APIs called via use_action(x). I've replaced rc.1's result() calls with value() calls in the Signal / action handling, like this:

let mut state = use_context::<Signal<CLIENT_STATE>>();

let mut fetch_challenge = use_action(get_challenge);
let mut fetch_solved = use_action(check_challenge);

let client_challenge = move |_| async move {
	state.set(CLIENT_STATE::WAITING);

	fetch_challenge.call().await;
	let binding = fetch_challenge.value().expect("Failed to fetch challenge").unwrap();

	let challenge = binding.try_read().unwrap(); // unpack signal
	let challenge_str = String::from_utf8(URL_SAFE.decode(challenge.deref()).unwrap()).unwrap();
	let solution = spow::wasm::pow_work(&challenge_str).expect("Failed to finish pow");
	let solution_str = URL_SAFE.encode(solution);

	fetch_solved.call(solution_str).await;
	let binding = fetch_solved.value().expect("Failed to fetch solved").unwrap();
	let check = binding.try_read().unwrap(); // unpack signal

	if *check {
		state.set(CLIENT_STATE::SOLVED)
	}
};

#[get("/api/challenge")]
pub async fn get_challenge() -> Result<String> {
    let challenge = SPow::new(60).map(|pow| pow.build_challenge()).unwrap();
    let challenge_str = URL_SAFE.encode(challenge);
    Ok(challenge_str)
}

#[get("/api/challenge/{pow}", sesh: tower_sessions::Session)]
pub async fn check_challenge(pow: String) -> Result<bool> {
    let challenge_str = String::from_utf8(URL_SAFE.decode(pow).unwrap()).unwrap();
    let challenge = SPow::validate(&challenge_str);
    match challenge {
        Ok(_) => {
            sesh.insert("AUTH_1", true).await.unwrap();
            Ok(true)
        },
        Err(_) => Ok(false),
    }
}

Hope that helps. My rc.2 adaptations have mostly been reverse-engineered so far and, while largely working on rc.1, might not reflect usage as intended.

critx-jeti avatar Oct 16 '25 21:10 critx-jeti

The logic to finish building the index for ServeConfig was moved to the launch method in https://github.com/DioxusLabs/dioxus/pull/4785 which breaks manual axum setups. Moving the logic into the renderer like this branch or restoring the builder and finalizing the index in the build method would fix the issue

ealmloff avatar Oct 16 '25 21:10 ealmloff

Ah, that indeed appears to be the culprit. In the main function, I currently use a middleware layer:

fn main() {
    #[cfg(not(feature = "server"))]
    dioxus::launch(app);

    #[cfg(feature = "server")]
    dioxus::serve(|| async {
        use dioxus::server::axum;

        let session_store = MemoryStore::default();
        let session_layer = SessionManagerLayer::new(session_store).with_secure(false);

        SPow::init_random().expect("Failed to initialize spow");

        Ok(dioxus::server::router(app).layer(session_layer))
    });
}

I'll temporarily downgrade to rc.1 and hold off for a while. Thanks a lot, @ealmloff !

critx-jeti avatar Oct 16 '25 21:10 critx-jeti

Same here, I have a custom axum setup indeed — I'll wait for rc.3 :)

fasterthanlime avatar Oct 17 '25 06:10 fasterthanlime

This was resolved by https://github.com/DioxusLabs/dioxus/pull/4806 which shipped in rc.3 :) Thanks y'all!

fasterthanlime avatar Oct 21 '25 11:10 fasterthanlime