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

adds feature axum_core that compiles for wasm target exposing server functions and ssr #3840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

conectado
Copy link

@conectado conectado commented Mar 7, 2025

The current axum feature is incompatible with wasm32-unknown-unknown target due to depending on tower-http for serving static files.

With this patch I add the axum_core feature which disables tower-http functions and enables targeting wasm32-unknown-unknown with server functions enabled and ssr.

Note that for this to work, server_fn depends on inventory and as stated in this docs depending on the context you might need to expose and call __wasm_call_ctors (I specifically needed that for Cloudflare workers)

Right now the feature isn't exposed by the main crate, I'm using it including the fullstack crate explicitly, I could add it to the main crate too!

@conectado conectado requested a review from a team as a code owner March 7, 2025 16:23
@ealmloff ealmloff added enhancement New feature or request fullstack related to the fullstack crate labels Mar 7, 2025
Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Re-exporting a different trait based on the feature flag can issues because features need to be additive. If we make the main axum extension trait a super trait of the wasm compatible axum trait it should fix that issue. The SSR rendering code should also be wasm compatible already so that could be included in the axum wasm feature flag. The main thing that is not compatible with wasm is serving the static files with tower-http. If we move that to a separate trait, the rest of the integration should work in wasm

@conectado
Copy link
Author

@ealmloff Thanks for the review! updated the PR for the feedback, lmk if there's something more to adjust

@conectado conectado requested a review from ealmloff March 8, 2025 01:36
@conectado conectado changed the title adds feature server_fn_axum that compiles for wasm target exposing server functions adds feature axum_wasm that compiles for wasm target exposing server functions and ssr Mar 8, 2025
Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better! The name axum_wasm might be slightly confusing if you need to import it in non-wasm targets. Maybe just axum_core for the wasm compatible axum integration and axum if you have access to both axum and a filesystem for native targets targets?

I expect tests will fail here again because the default features of axum were removed from the workspace. Adding default-features = true to the dev dependencies that rely on them should fix the issue

@conectado
Copy link
Author

Looks much better! The name axum_wasm might be slightly confusing if you need to import it in non-wasm targets. Maybe just axum_core for the wasm compatible axum integration and axum if you have access to both axum and a filesystem for native targets targets?

I expect tests will fail here again because the default features of axum were removed from the workspace. Adding default-features = true to the dev dependencies that rely on them should fix the issue

ah nice! I struggled to find a better name. feedback applied and also cleaned up the dependencies of each feature a bit more

@conectado conectado requested a review from ealmloff March 10, 2025 06:05
Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for working on this!

@conectado conectado changed the title adds feature axum_wasm that compiles for wasm target exposing server functions and ssr adds feature axum_core that compiles for wasm target exposing server functions and ssr Mar 10, 2025
@conectado
Copy link
Author

Hopefully CI should be passing now!

@conectado
Copy link
Author

my bad! now it should work

@conectado
Copy link
Author

rebased and conflicts resolved

@conectado
Copy link
Author

I think CI failure right now is unrelated

The current `axum` feature and `server` feature are incompatible with wasm32-unknown-unknown target
due to:
1. depends on axum features not compatible with wasm
2. SSR requires reading the filesystem for index.html

With this patch I add the `server_fn_axum` feature which disables SSR and enables targeting
wasm32-unknown-unknown with server functions enabled.

Note that for this to work, `server_fn` depends on `inventory` and as stated in this docs depending on
the context you might need to expose and call [`__wasm_call_ctors`](https://docs.rs/inventory/latest/inventory/#webassembly-and-constructors)
(I needed that specifically for cloudflare workers)

change axum_server_fn feature for axum_wasm and include SSR tools there

This change additionaly make axum_server_fn feature additive by exposing a different
`DioxusRouterWasmExt` with only the wasm-compatible parts instead of exposing the
`DioxusRouter` trait under the same name.

Docs are updated to reflect this change.

rename axum_wasm to axum_core and update docs

fix typo

re-enable default-features for axum in dioxus-cli

re-enable axum default-features for liveview

re-enable default-features for axum for playwright-tests
@conectado
Copy link
Author

rebased and conflicts solved! :)

@conectado
Copy link
Author

Just checking in on this PR—let me know if there's anything else I can do to help get it merged. No rush, just asking!

@ealmloff
Copy link
Member

Just checking in on this PR—let me know if there's anything else I can do to help get it merged. No rush, just asking!

Looks great to me, just waiting for a review from Jon before this can be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fullstack related to the fullstack crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants