fix(fullstack): use target_arch instead of feature flags for server/web platform detection#5302
Closed
raxosiris wants to merge 1 commit intoDioxusLabs:mainfrom
Closed
fix(fullstack): use target_arch instead of feature flags for server/web platform detection#5302raxosiris wants to merge 1 commit intoDioxusLabs:mainfrom
raxosiris wants to merge 1 commit intoDioxusLabs:mainfrom
Conversation
Cargo feature unification enables both `web` and `server` features simultaneously in fullstack workspaces, breaking SSR hydration.
Member
|
We don't rely on the target to determine web vs server builds because the server can also be compiled to wasm on serverless targets like spin/fly.io. Your setup instructions sound very similar to the dioxus template workspace fullstack + router setup which does work correctly with hydration. Can you compare your feature setup to the template to narrow down the issue? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In fullstack workspaces with multiple crates, Cargo's feature unification enables both
webandserverfeatures simultaneously ondioxus-fullstack-core. This causes SSR hydration to break because code guarded by#[cfg(feature = "server")]and#[cfg(feature = "web")]both compiles and executes.For example, in
history.rs, the server branch (entry.insert()) runs in WASM instead of the client branch (entry.get()), causing hydration data to be overwritten instead of read.Reproduction
The
uicrate unconditionally enablesfullstack, which pulls in bothdioxus-fullstack-core/webanddioxus-fullstack-core/serverthrough transitive feature resolution.Run
dx serve— SSR renders correctly on the server, but WASM hydration fails because server-side code paths execute in the browser (e.g.,entry.insert()instead ofentry.get()in history.rs).Fix
Replace
cfg(feature = "server")/cfg(feature = "web")withcfg(not(target_arch = "wasm32"))/cfg(target_arch = "wasm32")in platform-specific code paths.Why this works:
target_archis determined by the compilation target, not Cargo features, so it can never be both values simultaneously.dx servecompiles the server for native (x86_64/aarch64) and the client for wasm32 — these are separate compilation units immune to feature unification.Why this is safe for other platforms:
fullstack-corefullstack-coreis only compiled for server (viadioxus-server) and web client (viadioxus-webwithhydrate)fullstackcrate itself already usestarget_arch = "wasm32"for websocket transport inclient.rs, establishing this as the correct patternChanges
fullstack-core/src/history.rs— Route finalization: server inserts route, client reads itfullstack-core/src/loader.rs— Data loader serialization directionfullstack-core/src/server_cached.rs— Cache write (server) vs read (client)fullstack-core/src/server_future.rs— Server future serialization directionfullstack-core/src/transport.rs—is_hydrating()andserialize_context()platform detectionfullstack-server/src/ssr.rs— Added explicit type annotation tohas_context::<HydrationContext>()web/src/lib.rs—should_hydratenow respects runtime config only, removingcfg!(feature = "hydrate")override that could be incorrectly triggered by feature unification