DioxusLabs / DioxusLabs/dioxus
dioxus-fullstack-core: silently broken SSR hydration when both web and server features are enabled
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Summary
When `dioxus-fullstack-core` is compiled with both `web` and `server` features enabled simultaneously, SSR hydration silently breaks. The `serialize_context()` function uses `#[cfg(feature = "web")]` / `#[cfg(not(feature = "web"))]` to branch between client
and server code paths. When both features are on, the `web` path always wins — even on the server — causing `use_loader` data to never be serialized into the hydration blob.
## Steps to Reproduce
1. Create a Dioxus fullstack app with `use_loader` + `SuspenseBoundary`
2. Enable both `web` and `server` features on `dioxus-fullstack-core` (e.g. via Cargo feature unification)
3. Run `dx serve`
4. Open any page with `use_loader(...)?`
## Expected Behavior
SSR renders the page and sends hydration data to the client. Client hydrates without errors.
## Actual Behavior
- `window.initial_dioxus_hydration_data` contains only the error entry (4 bytes) — zero loader data
- Client receives no serialized server function results
- Client's virtual DOM has fewer nodes than the server HTML
- Hydration crashes: `Cannot read properties of undefined (reading 'toString')` in `hydrate_node`
## Root Cause
https://github.com/DioxusLabs/dioxus/blob/e5b9c39f4e53ce86c0b1af2fb077913cf28f9365/packages/fullstack-core/src/transport.rs#L162-L180
When `web` is enabled on the server, the `else` branch returns a throwaway `HydrationContext` (the thread-local `CONTEXT` is never set on the server). This context is never `provide_context()`-ed into the scope, so the SSR tree walk in `serialize_server_data`
finds no hydration data in any scope.
## Proposed Fix
Add a compile-time error in `dioxus-fullstack` when both features are enabled:
```rust
#[cfg(all(feature = "web", feature = "server"))]
compile_error!(
"The `web` and `server` features of `dioxus-fullstack` are mutually exclusive."
);
```
**Environment:**
- Dioxus version: v0.7.4
- Rust version: 1.86.0
- OS info: macOS 15.4 (aarch64)
- App platform: web (fullstack SSR)
**Questionnaire**
I would like to fix and I have a solution.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.