Skip to content

Conversation

@s3bba
Copy link
Contributor

@s3bba s3bba commented Aug 12, 2025

This is an attempt to fix magic number/word error when in fullstack mode and hot patching is active:

13:39:49 [web] panicked at /home/sebba/.cargo/git/checkouts/dioxus-d8abd2ecf6e8b5b4/a519fba/packages/subsecond/subsecond/src/lib.rs:647:10:
called `Result::unwrap()` on an `Err` value: JsValue(CompileError: wasm validation error: at offset 4: failed to match magic number)

Why this happens?
This bug is present only in fullstack mode, the cause is axum router that serves static assets needs to be rebuilt to serve newly added file, and rebuild was only triggered if incoming hot-reload message included a server patch jumptable.

This meant if client didn't generate wasm patch file before server patch was ready, router would respond with a 404 even if the file was present in the filesystem, and magic number error would apear

The fix:
I'm not sure if this is the right way to fix this, but it does work in web and desktop targets without issues.
Currently change is very simple, router rebuild logic was moved outside conditional that required message to be a server patch, so router now gets rebuilt on every patch

Limitations of the current fix:
There is one "downside" to this patch, if developers setup axum server manually dev tools are never connected, see launch.rs for more info

The manual approach looks something like this, taken from https://dioxuslabs.com/learn/0.6/guides/fullstack/axum

#[cfg(feature = "server")]
async fn launch_server(component: fn() -> Element) {
    use std::net::{IpAddr, Ipv4Addr, SocketAddr};

    // Get the address the server should run on. If the CLI is running, the CLI proxies fullstack into the main address
    // and we use the generated address the CLI gives us
    let ip =
        dioxus::cli_config::server_ip().unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
    let port = dioxus::cli_config::server_port().unwrap_or(8080);
    let address = SocketAddr::new(ip, port);
    let listener = tokio::net::TcpListener::bind(address).await.unwrap();
    let router = axum::Router::new()
        // serve_dioxus_application adds routes to server side render the application, serve static assets, and register server functions
        .serve_dioxus_application(ServeConfigBuilder::default(), App)
        .into_make_service();
    axum::serve(listener, router).await.unwrap();
}

@jkelleyrtp jkelleyrtp merged commit 627386c into DioxusLabs:main Sep 3, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants