Skip to content

fix(fullstack): allow the server URL to be set more than once - #5704

Merged
ealmloff merged 1 commit into
DioxusLabs:mainfrom
SilasMarvin:resettable-server-url
Jul 26, 2026
Merged

fix(fullstack): allow the server URL to be set more than once#5704
ealmloff merged 1 commit into
DioxusLabs:mainfrom
SilasMarvin:resettable-server-url

Conversation

@SilasMarvin

@SilasMarvin SilasMarvin commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

set_server_url stored the root URL in a OnceLock and unwrapped, so a second call panicked — pinning the base URL for the life of the process. A native client that talks to more than one backend can't work with that.

Swaps the OnceLock for an RwLock<Option<&'static str>> so the most recent value wins. fetch_inner already reads the URL per request, so the change applies to the next server-function call with no restart. get_server_url still returns "" when unset, so launch's devserver-default check is unaffected. Mirrors the neighbouring REQUEST_HEADERS, already a re-settable Mutex.

Also removes a latent panic: the native and web base-path blocks in launch can compile into one binary and both call set_server_url, the second unconditionally — panicking whenever base_path() is Some.

Tested: cargo fmt, check, clippy -D warnings, test --all all pass.

`set_server_url` stored into a `OnceLock` and unwrapped the result, so a
second call panicked. That makes the base URL a permanent property of the
process, which a client that talks to more than one backend cannot work
with: the backend has to be chosen before `launch`, since `launch` claims
the slot itself when it is still empty, and it can never change afterwards.

Store it in an `RwLock` instead so the most recent value wins. `fetch_inner`
already reads the URL as each request is built, so a change applies to the
next server function call with no restart. `get_server_url` still returns
`""` when unset, so `launch`'s "set the devserver default if empty" check
is unaffected.

This also removes a latent panic in `launch`: the native block
(`cfg(any(desktop, mobile, native))`) and the web base-path block both call
`set_server_url`, and the second does so unconditionally, so a binary
compiled with both feature sets panicked inside the framework whenever
`dioxus_cli_config::base_path()` returned `Some`.

The neighbouring `REQUEST_HEADERS` is already a `Mutex` with a re-settable
`set_request_headers`, so this brings the two client-configuration globals
into line.
@SilasMarvin
SilasMarvin requested a review from a team as a code owner July 25, 2026 21:21

@ealmloff ealmloff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems reasonable. It lets you build re-exports of specific server functions that set and unset the url for the call. We should probably have an api to map the url for specific re-exports in the long term, but this is a fine workaround for now

@ealmloff
ealmloff merged commit 0299a03 into DioxusLabs:main Jul 26, 2026
20 of 37 checks passed
@SilasMarvin

Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge @ealmloff

This is a super cool project. I really appreciate the work you and the team are doing here.

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