Skip to content

Conversation

@DrewRidley
Copy link
Contributor

Motivation
Currently, WASM servers cannot use serve_dioxus_application because it's trait extension only has an implementation for non-WASM targets. If users try to manually implement this functionality, they encounter difficulty accessing the private context_providers field in the ServeConfig, and have to rewrite a lot of the core logic for SSR which has a maintenance burden.

Solution

This PR adds conditional compilation for the serve_static_assets method:

  • For non-WASM targets: maintains the existing implementation that serves static assets from the public directory
  • For WASM targets: provides a simple implementation that just returns self (no-op)

This allows WASM servers to use the same serve_dioxus_application API as non-WASM servers, simplifying code that needs to work across both environments. Since this trait is never used on wasm currently, it should not introduce a breaking change.

@DrewRidley DrewRidley requested a review from a team as a code owner May 22, 2025 03:33
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.

I can see how exposing the logic to handle server functions and the default route renderer is useful in wasm, but the serve_static_assets function is documented as serving static assets which we can't do in wasm servers. How about a new method with the same signature on DioxusRouterFnExt that just serves the fullstack server function and rendering endpoints instead?

@DrewRidley
Copy link
Contributor Author

After re-reading the comment, I would have to agree that this approach makes more sense.
The requested changes have been implemented, and compilation it was tested with:

--target wasm32-unknown-unknown --no-default-features --features document,core

Let me know if theres anything else I can do!

@ealmloff ealmloff added breaking This is a breaking change fullstack related to the fullstack crate enhancement New feature or request labels May 23, 2025
@DrewRidley
Copy link
Contributor Author

Those two tests seem to be failing on main also, is there anything I need to change in this PR?

Also, I was wondering if I could incorporate a fullstack-core feature for dioxus which does all the feature gating for wasm targets, just to massively simplify the cargo.toml for applications targeting wasm for SSR.

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! Workflow failures are unrelated.

@ealmloff ealmloff merged commit eb15b42 into DioxusLabs:main May 24, 2025
14 of 17 checks passed
@ealmloff
Copy link
Member

Also, I was wondering if I could incorporate a fullstack-core feature for dioxus which does all the feature gating for wasm targets, just to massively simplify the cargo.toml for applications targeting wasm for SSR.

I think that would make sense. What is your setup for serving a fullstack app with a wasm backend? We look for the fullstack feature in the CLI to determine what platform you are serving. We don't support wasm backends in the CLI, and at this point the tooling seems like it is tied to each backend provider so I don't think it makes sense to add support yet. If we don't change the CLI and just add the feature, dx serve will launch the app as a web app which will panic immediately because there is no hydration.

@DrewRidley
Copy link
Contributor Author

DrewRidley commented May 25, 2025

Atm, I have to do:

dioxus = { git = "https://github.com/DrewRidley/dioxus.git" }
dioxus-server = { git = "https://github.com/DrewRidley/dioxus.git", features = [
	"document",
	"core",
], default-features = false }
dioxus-router = { git = "https://github.com/DrewRidley/dioxus.git", features = [
], default-features = false }
dioxus_server_macro = { git = "https://github.com/DrewRidley/dioxus.git", features = [
], default-features = false }
server_fn = { version = "0.8.2", features = ["axum-no-default", "browser"] }

In my code on my own app, which is a bit cumbersome, and makes it harder to mix regular fullstack with cloudflare. Ideally theres some way to directly target features for a wasm server, and it would be even better if it could be hooked into the dx cli to automatically build and hot patch a wasm server binary, but that might be something for the future.

Thanks for merging the PR. Let me know if there is any interest in a more direct integration, I would be happy to explore the idea further and potentially put forward a follow-up PR.

AnteDeliria pushed a commit to AnteDeliria/dioxus that referenced this pull request Jun 2, 2025
* optional asset serving

* optional asset serving

* Add serve_api_application for WASM environments

* fix cfg

* remove old placeholder
AnteDeliria pushed a commit to AnteDeliria/dioxus that referenced this pull request Jul 23, 2025
* optional asset serving

* optional asset serving

* Add serve_api_application for WASM environments

* fix cfg

* remove old placeholder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking This is a breaking change 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